关于, 我一直在尝试多种方法来按CompanyName和Creation Date过滤记录, CompanyName的过滤器工作正常,但是Datapicker中CreateDate的过滤器不断带给我所有记录。我认为您必须使用模型转换CreateDate:
new sap.ui.model.type.DateTimeOffset({source: {pattern: "yyyy-MM-dd"}});.
有人可以帮我吗?
CreateDate属性
<Property Name="CreateDate" Type="Edm.DateTimeOffset"/>
这是JSON返回的日期=“ CreateDate”:“ 2018-02-01”,
myView.xml
<fb:FilterBar header="Lists" clear="onClear" search="onSearch" showClearButton="true" useToolbar="false" showClearOnFB="true">
<fb:filterGroupItems>
<fb:FilterGroupItem visibleInFilterBar="true" groupName="Partner" groupTitle="{i18n>filterPartnerInfo}" name="PartnerDate" label="{i18n>filterPartnerDate}">
<fb:control>
<DatePicker
value="{ path: 'filters>/date',
type: 'sap.ui.model.odata.type.DateTimeOffset',
formatOptions: {
source: {pattern: 'yyyy-MM-dd'},
style: 'medium'
}
}
"/>
</fb:control>
</fb:FilterGroupItem>
</fb:filterGroupItems>
</fb:FilterBar>
<Table id="idProductsTable"
inset="false"
items="{
path: '/BusinessPartners',
templateShareable : false,
sorter: {
path: 'CardCode'
}
}">
<columns>
<Column
width="12em">
<Text text="Name" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true">
<Text text="Date" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier
text="{CompanyName}"/>
<Text
text="{
path: 'CreateDate',
type: 'sap.ui.model.type.Date',
formatOptions: {
style: 'medium',
source: {
pattern: 'yyyy/MM/dd'
}
}
}" />
</cells>
</ColumnListItem>
</items>
</Table>
myController.js
onSearch: function(oEvent) {
var oFilterModel = this.getView().getModel("filters");
var sName = oFilterModel.getProperty("/name");
var sDate = oFilterModel.getProperty("/date");
var aFilters = [];
if( sName ) {
aFilters.push( new Filter("CompanyName", FilterOperator.Contains, sName.toUpperCase()) );
}
if( sDate ) {
aFilters.push( new Filter("CreateDate", FilterOperator.Contains, sDate) );
}
this.byId("idPartnerTable").getBinding("items").filter(aFilters);
},
答案 0 :(得分:0)
Hui Json,您可以尝试使用日期过滤器类型:
onSearch: function(oEvent) {
// Init filters
var aFilters = [];
var oFilterModel = this.getView().getModel("filters");
var sName = oFilterModel.getProperty("/name");
var sDate = oFilterModel.getProperty("/date");
// Check if the name has been added as a filter
if( sName ) {
aFilters.push( new Filter("CompanyName", FilterOperator.Contains, sName.toUpperCase()) );
}
// This is the basic parse method, if you want to get more advanced use moment.js or parse date in another way
var dDateStart = new Date(sDate);
// Check if the date is valid
if( dDateStart instanceof Date && !isNaN(dDateStart) ) {
var dDateEnd = new Date(dDateStart);
// Set first date as start of day
dDateStart.setMilliseconds(0);
dDateStart.setSeconds(0);
dDateStart.setMinutes(0);
dDateStart.setHours(0);
// Set second date as end of day
dDateEnd.setMilliseconds(0);
dDateEnd.setSeconds(59);
dDateEnd.setMinutes(59);
dDateEnd.setHours(23);
aFilters.push(new Filter({
path: "CreateDate",
operator: FilterOperator.BT,
value1: dDateStart,
value2: dDateEnd
})));
}
// Trigger the filter on the table
this.byId("idPartnerTable").getBinding("items").filter(aFilters);
}