jQWidgets Forums

jQuery UI Widgets Forums Grid Applying grid state with loadstate before grid initialization

This topic contains 4 replies, has 2 voices, and was last updated by  TP_DTNA 8 years, 6 months ago.

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

  • TP_DTNA
    Participant

    Is there an easy way to load a grid state with “loadstate” before initializing the grid? This almost works with the autoloadstate grid property, but I need to do it manually with loadstate for several reasons. Please note that I am using virtualmode = true

    The best way I’ve figured out so far is to call it asynchronously (inside a setTimeout call) once on the “bindingcomplete” event. That ultimately gets the job done, but it starts out with the default state and loads its data once before applying the grid settings. My code for that looks like this:

    
       $grid.one('bindingcomplete', function() {
          setTimeout(function() {
            $grid.jqxGrid('loadstate', gridState);
          }, 0);
        });
    
    

    I’ve looked for an easy way to do this, but haven’t found one yet. My current plan is to hack the jqw source until I can achieve this result, but I’m hoping someone out there might know something I don’t and save me time with a helpful suggestion.
    Thanks!


    Christopher
    Participant

    Hi TP_DTNA,

    Try calling the loadstate function on the ready(not “bindincompleted”) event, without a timeout. It should load the new state as soon as the jqxGrid is visualized.

    Best Regards,
    Christopher

    jQWidgets Team
    http://www.jqwidgets.com


    TP_DTNA
    Participant

    While not technically an event, that ready callback approach works much better. Things like the column positions and sizes work great, but for filters and sorts it still displays a non-filtered and non-sorted view before the filters and sort apply and it then loads the correct thing the user should see.

    I want to polish my project up to look nice and load correctly the first time without things flickering like that. Is there a way to have the sort and filters apply before it starts making calls to the loadServerData()?

    Thank you for the help, the improvement I’ve already gained from your previous suggestion feels nice.


    Christopher
    Participant

    Hi TP_DTNA,

    Your best option is to apply the desired behavior in the ready function. You can apply filters immediately after the jqxGrid is in ready state.
    For example:
    http://jsfiddle.net/Eeume/80/

    The same goes for sorting using the sortby function.

    Best Regards,
    Christopher

    jQWidgets Team
    http://www.jqwidgets.com


    TP_DTNA
    Participant

    I gave your suggestion a fair try. Should I apply filters before or after loading the state? Should I remove those filters from the state when applying them separately or leave them in? I said “yes” and “no” to these questions and tested them upside down, inside out, backwards, and sideways. While I was able to trigger all kinds of exciting bugs, every single thing I tried still resulted in an unwanted call to loadServerData();

    So I took a simpler approach and got pretty close to the result I’m ultimately after with this workaround:
    I keep a variable (let’s call it “readyState”) in a scope shared by both the ready function and loadServerData to keep track of the ready state. If loadServerData is called prematurely (before being “ready”), it simply gives an empty data set to the callback as though it made an ajax call that came back with zero results, but without the ajax call and wasted server load.

    The ready function then sets that readyState to true so that when loadServerData() is called a second time, it serves up data like normal.

    It’s a somewhat lengthy workaround, but gets the job done. To be honest, my experience with the state save and load features (including autosave/load) is that they are quite buggy and would not be very hard to fix and improve. There are many examples, but one is if I try to use the auto features in this setup, it will not apply the filter until after the user has scrolled once, even though the filter icon shows. Seems to be connected to what is happening with the premature data load.

    Thanks for your help toward finding a working solution.

    Edit: if anyone is also having trouble with virtualmode grids handling empty result sets (like a blank database or empty search query), I found a bug and fixed it: http://www.jqwidgets.com/community/topic/handling-empty-grids-in-virtual-mode/ – That might be required if you implement the fix I described above.

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

You must be logged in to reply to this topic.