jQuery UI Widgets Forums Grid Show the filters applied in the grid and restrict DB hit

This topic contains 13 replies, has 2 voices, and was last updated by  Sibeesh Venu 8 years, 3 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author

  • Sibeesh Venu
    Participant

    Hi,
    I have implemented a grid with server side paging, sorting, filtering. Now my user has saved that grid with all the sorting, filtering information. I have generated a query with all these information. That means, when I load that grid again, I am giving the filtered and sorted data to the grid. Even though I have given the sorted, filtered data, now the events hits the DB since I am applying the filtering and sorting properties as below. In this situation, If I have sorted 7 fields in the grid, it hits DB 8 times (7 for applying filter and one for loading the grid for the first time)

    $(openFrom + "#jqxgrid").jqxGrid('sortby', sessionStorage.getItem("GridSortColumn"), sortdirectionvalue);

     $(openFrom + "#jqxgrid").jqxGrid('addfilter', currentColumnFilterValue['columnname'], filterGroup);
      $(openFrom + "#jqxgrid").jqxGrid('applyfilters');

    Here is my source object.

    var source =
                          {
                              datafields: DataFields,
                              datatype: "json",
                              async: false,//If it is true, server side filtering and sorting won't work together
                              url: '../Widget/GetDataForGrid/',
                              type: 'POST',
                              sort: function () {
                              },
                              filter: function () {
                              },
                              beforeprocessing: function (data) {
                              }
                          };

    So my requirement is, I just need to show the filter, sort selection in the grid without going to DB. This is applicable only for the first time(When the grid with sorted, filtered information loads first). And when the user click the filter again or user tries to sort another field, it should work as in server side filtering and sorting.
    Any help is much appreciated.

    • This topic was modified 8 years, 3 months ago by  Sibeesh Venu.

    Peter Stoev
    Keymaster

    Hi Sibeesh Venu,

    Sorting & Filtering does not make server call unless you make it through jqxGrid’s API like “updatebounddata” method call. Also you can’t have server paging with local sorting & filtering which I see is your case. I suggest you to look at our demos at first in order to learn how to implement correctly Server Paging with Server sorting and filtering. Example: http://www.jqwidgets.com/jquery-widgets-demo/demos/php/serverfiltering_paging_and_sorting.htm?arctic. As you see, the sort and filter functions in our demo are implemented.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Sibeesh Venu
    Participant

    Sorry I forgot to mention. I have already used update bound data.

    $(openFrom + "#jqxgrid").jqxGrid('updatebounddata', 'sort');
    $(openFrom + "#jqxgrid").jqxGrid('updatebounddata', 'filter');


    Sibeesh Venu
    Participant

    Hi Peter,
    Here my requirement is not local filtering and sorting. My need is to just show the selection of those filtered and sorted data, since I have already applied filtered and sorted data to the grid. So that I can reduce the DB hit. As I said above, when user tries to filter or sort after grid is loaded, everything should work as in server side demo.


    Peter Stoev
    Keymaster

    Hi Sibeesh Venu,

    You have to do it exactly as in our demo. If you have 2 updatebounddata calls, you will have 2 server calls, as well.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Sibeesh Venu
    Participant

    Hi Peter,
    Thanks for your reply. So is there any alternative for $(openFrom + "#jqxgrid").jqxGrid('applyfilters');?


    Peter Stoev
    Keymaster

    Hi Sibeesh Venu,

    Your problem is not applyfitlers but the fact that you call 2 times updatebounddata.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Sibeesh Venu
    Participant

    Hi Peter,
    Thanks for your reply. So is there anyway we can call updatebounddata only once with all the filters and sort. Please suggest me an idea. Thanks in advance


    Peter Stoev
    Keymaster

    Hi Sibeesh Venu,

    call it without params.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Sibeesh Venu
    Participant

    Hi Peter,
    Thanks for the reply. Do you mean like below?

    $(openFrom + "#jqxgrid").jqxGrid('updatebounddata', '');
    $(openFrom + "#jqxgrid").jqxGrid('updatebounddata', '');
    • This reply was modified 8 years, 3 months ago by  Sibeesh Venu.

    Peter Stoev
    Keymaster

    Hi Sibeesh Venu,

    No. I mean 1 method call = 1 DB call, 2 method calls = 2 DB calls.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Sibeesh Venu
    Participant

    Hi Peter Stoev,
    What is the event name which gets called automatically once after sort and filter? If there is such an event, I can call updatebounddata there right? And Is there any common updatebounddata function. Something as $(openFrom + "#jqxgrid").jqxGrid('updatebounddata')?


    Sibeesh Venu
    Participant

    I have solved it myself.

    I created a variable and initiated it in the document ready as follows.

    var isFilterSortGrid = false;
    Change sort filter functions in source object as follows.

    sort: function () {
                          if (isFilterSortGrid) {
                              $("#jqxgrid").jqxGrid('updatebounddata', 'sort');
                          }
                      },
    filter: function () {
                          if (isFilterSortGrid) {
                              $("#jqxgrid").jqxGrid('updatebounddata', 'filter');
                          }
                      }

    And finally in filter and clear button click I made that variable true again.

    $(document).on('click', '#filterbuttonjqxgrid', function () {
      isFilterSortGrid = true;
    });
    
    $(document).on('click', '#filterclearbuttonjqxgrid', function () {
     isFilterSortGrid = true;
    });

    I am applying the filter and sorting as normal, so that the filter selection will be there.


    Sibeesh Venu
    Participant

    But I am facing an another issue now. My call to set the variable is getting fired after the normal filter function fired.

    $(document).on('click', '#filterclearbuttonjqxgrid', function () {
        isFilterSortGrid = true;
    });

    How can we make the click event to be fired first? Any help is much appreciated. Thanks in advance

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.