Tina Chen
Tina Chen

Reputation: 2030

How to filter DateTime data using sap.ui.model.Filter?

I've tried to filter DateTime data using sap.ui.model.Filter:

oTableSearchState = [new Filter([ new Filter("Date", FilterOperator.Contains, sQuery), new Filter("Another_Date", FilterOperator.Contains, sQuery), ])]

it return 400 Bad String. I found that the odata request is ...$filter substringof(,Date). So I know it's not correct that using a "string filter" to filter date.

what I need is ...$filter= Date ge datetime'2016-08-17T16:00:00Z' and Date lt datetime'2016-08-18T16:00:00' Can I do that with sap.ui.model.Filter? Or the only way to do that is put filter parameters together by my own hands?

Upvotes: 0

Views: 10020

Answers (1)

Jaro
Jaro

Reputation: 1754

Yes you can, please use sap.ui.model.Fitler as (using operator BT):

new sap.ui.model.Filter("Date", sap.ui.model.FilterOperator.BT, dateFrom, dateTo)

Selection of dates can be done by handling sap.m.DateRangeSelection event "change"

handleChange : function(oEvent){
        dateFrom = oEvent.getParameter("from");
        dateTo   = oEvent.getParameter("to");
}

Upvotes: 3

Related Questions