Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid Remote Data, Sort Locally

Tags:

jqgrid

I have a grid that I am retrieving the entire set of data for, then want the users to have the ability to sort the resulting data. I am using the following attributes, but the grid does not sort. It's also worth mentioning after the user clicks a button, I will make an AJAX call then I will need to refresh from the source, but since I'm pulling all of the data to the client every time, I shouldn't need to go back to the server just to sort.

loadonce: true, // to enable sorting on client side
sortable: true //to enable sorting

Any suggestions are greatly appreciated!

like image 662
Benny Avatar asked Feb 02 '12 22:02

Benny


2 Answers

I just noticed something. You can use the loadComplete parameter when defining the grid.

                    loadComplete: function() {
                                    // add a function here that waits for a short amount of time, like 100msecs
                                    jQuery("#list1").jqGrid('setGridParam', {
                                            datatype:'local',
                                            sortname:'name',
                                            sortorder:'asc',
                                            page:1
                                    }).trigger("reloadGrid");
                    }

Note that I use my data locally and when I need a refresh put the datatype back to xml.

Important: this in itself will not work: you need to have a small amount of time waiting before triggering reloadGrid(executing the line). Otherwise you won't see a difference in the output.

like image 58
th3penguinwhisperer Avatar answered Oct 03 '22 10:10

th3penguinwhisperer


I'm not sure but it seems to me that you want to achieve your sorting locally whereas your searches remotely. I had the same requirement and I did it like this: Make 'Search' remote and everything else (sorting, pagination, etc) local in jqGrid

like image 41
keithxm23 Avatar answered Oct 03 '22 10:10

keithxm23