Prevent double post on filter/sort reset

5 posts, 0 answers
  1. Erik
    Erik avatar
    7 posts
    Member since:
    Sep 2015

    Posted 31 Mar Link to this post

    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

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 04 Apr Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Erik
    Erik avatar
    7 posts
    Member since:
    Sep 2015

    Posted 04 Apr Link to this post

    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

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 06 Apr Link to this post

    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
  6. Erik
    Erik avatar
    7 posts
    Member since:
    Sep 2015

    Posted 07 Apr in reply to Boyan Dimitrov Link to this post

    Thanks for the assist!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready