aslagle / reactive-table

A reactive table designed for Meteor
https://atmospherejs.com/aslagle/reactive-table
Other
328 stars 138 forks source link

Date custom filter on reactive table collection not working #489

Open Abhimanyu-Jana opened 6 years ago

Abhimanyu-Jana commented 6 years ago

I have a reactive-table with custom filter defined on a date column


Template.displayoptions.created = function () {
    this.timeFilter = new ReactiveTable.Filter('time-filter', ['deadline']);
};

Template.displayoptions.events({
'click .form-check-input'(event,template) {
    var timefilter = template.find('#timefilter:checked').value;

    var today = new Date();
    var thisweek = new Date(moment(today).add(7, 'days'));
    var thismonth = new Date(moment(today).add(1, 'month'));

    switch(timefilter){
        case "today":
            template.timeFilter.set({"$gte": today});
            break;
        case "thisweek":
            template.timeFilter.set({"$and":[{"$gte": today}, {"$lt" : thisweek}]});
            break;
        case "thismonth":
            template.timeFilter.set({"$and":[{"$gte": today}, {"$lt" : thismonth}]});
            break;
    }        

}

});

When the event is triggered (radio button to select today/week/month), the table flashes but data remains unchanged. What could be missing?

rowsPerPage: 5,
filters: ['time-filter'],
showNavigationRowsPerPage: false,
showFilter: false
Abhimanyu-Jana commented 6 years ago

I just read that and/or do not work in custom filters. However the 'today' filter also does not work which has no logical operators defined.

Abhimanyu-Jana commented 6 years ago

Some more info:

The collection is published with existing filter on the date column on server side. Date is stored as date object in mongo, but displayed as YYYY-MM-DD in table.

fn: function(value){ return moment(value).format('YYYY-MM-DD');