Cannot get datasource to acknowledge changes to filter

1 Answer 73 Views
Data Source Filter Grid
Eric
Top achievements
Rank 1
Eric asked on 25 Aug 2023, 01:06 PM | edited on 25 Aug 2023, 01:09 PM

I have a kendo grid in JSTL format where I'm trying to override a filter choice for date (making the filter look for the span of an entire day like in this example. But setting a simple hardcoded filtergives no results in the kendo grid, even when there are results matching the filter:

let startOfFilterDate = new Date(2000,1,1,0,0,0) 
let endOfFilterDate = new Date(2000,1,1,23,59,59) 
var filter = { 
  logic: "and", 
  filters: [ 
    { field: "date", operator: "gte", value: startOfFilterDate }, 
    { field: "date", operator: "lte", value: endOfFilterDate } 
  ] 
}; 
e.sender.dataSource.filter(filter);

I've tried putting in various places...

1) <kendo:dataSource-change></kendo:dataSource-change

2) <kendo:grid name="search-result-grid" ... filterable="true" columnMenu="true" columnMenuInit="doFilter">

And then my "doFilter" method is pretty much the same as the given example linked to above.

If I console.log the dataSource.filter, it shows that the filters are there. But the datasource is not being updated/refreshed with the filter for whatever reason.

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Denchev
Telerik team
answered on 30 Aug 2023, 08:25 AM

Hi, Eric,

Thank you for the provided sample.

As far as I understand your requirement is to intercept the filter before it is applied to the DataSource and modify it? If that is the case, then you can use the filter event of the Grid instead of filterMenuInit.

        filter: function(e) {
          if (e.filter && e.field === "age") {
            // Prevent the default filter action.
            e.preventDefault();
            // Modify the value of the filter from the first input.
            e.filter.filters[0].value = 33;
            // Apply the modified filter to the dataSource.
            e.sender.dataSource.filter(e.filter);
          }
        }

Dojo

https://dojo.telerik.com/@gdenchev/ABIveXeS 

To test the example, you can open the filter menu for the 'age' column. Type '30' in the first input and apply the filter. The row with age '33' will be displayed instead(because the filter has been modified).

Best Regards,
Georgi Denchev
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
Data Source Filter Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or