Reputation: 5
How can I filter a listView (mobile) items based on 2 dates. I have 2 html date inputs: one 'start date' and another 'end date'. ListView needs to show a range of items with date between those two values from date inputs. How can I achieve this ?
My approach was to iterate through the model array to compare date field with needed date store in a filtered array this item if ok, and after all items were processed refresh list view. but it did not work.
Upvotes: 0
Views: 2119
Reputation: 3055
You should be able to filter the dataSource the list is bound to based on the date field.
filterOnDate: function() {
var filter = { logic: "and", filters: [] };
filter.filters.push({ field: "birthday", operator: "gt", value: new Date(viewModel.startDate)});
filter.filters.push({ field: "birthday", operator: "lt", value: new Date(viewModel.endDate)});
viewModel.dataSource.filter(filter);
}
See jsbin http://jsbin.com/EXUGiQE/4/edit
Upvotes: 2