This is a migrated thread and some comments may be shown as answers.

Prevent double post on filter/sort reset

4 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 2
Erik asked on 31 Mar 2016, 06:10 PM

I have a grid with a large data set and I have a button that clears filters and sorting but each one causes a refresh of the data:

    $(function () {
        $("#reset").click(function (e) {
            e.preventDefault();
            var datasource = $("#grid").data("kendoGrid").dataSource;
            //Clear filters:
            datasource.filter([]);

          //Clear sorting:
            datasource.sort({});
        });
    });

Is there a way to combine this to only refresh the data once.

Thanks,

Erik

4 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 04 Apr 2016, 08:58 AM

Hello Erik,

 

The query method of the Kendo UI DataSource is designed for such cases. 

 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Erik
Top achievements
Rank 2
answered on 04 Apr 2016, 11:57 AM

Thanks but I cannot seem to get the syntax correct and the documentation is void of any useful examples.  Could you please provide a snippet showing how to do this for my grid. I'm not really sure how to reference the datasource in the Query as the example shows creating a static data var.  One exception I get is .filter is not a function.  

Any help would be great,

-Erik

0
Boyan Dimitrov
Telerik team
answered on 06 Apr 2016, 08:40 AM

Hello Erik,

I am not sure why it is necessary to access the dataSource itself to clear the sort and filter expression. The code that will clear the applied sorting and filter expression will look like: 

$(function () {
       $("#reset").click(function (e) {
           e.preventDefault();
           var datasource = $("#grid").data("kendoGrid").dataSource;
           datasource .query({sort: {}, filter: {}});
       });
   });

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Erik
Top achievements
Rank 2
answered on 07 Apr 2016, 01:27 PM
Thanks for the assist!
Tags
Grid
Asked by
Erik
Top achievements
Rank 2
Answers by
Boyan Dimitrov
Telerik team
Erik
Top achievements
Rank 2
Share this question
or