views:

327

answers:

2

I have a jqGrid in an ASP.NET MVC View with the option multiselect:true. There are over 200 records displayed in the grid, so I have paging enabled. This works great, but when I navigate from page to page, the selections are lost when I navigate.

Is there a good, clean way to persist the selections so that they are maintained while paging?

A: 

Managed it with some javascript trickery:

    var pages = [];
    onSelectRow: function(rowid, status) {
                    var pageId = $('#grdApplications').getGridParam('page');
                    var selRows = [];
                    if (status) {
                        //item selected, add index to array
                        if (pages[pageId] == null) {
                            pages[pageId] = [];
                        }
                        selRows = pages[pageId];

                        if (selRows.indexOf(rowid) == -1)
                        { selRows.push(rowid); }
                    }
                    else {
                        //item deselected, remove from array
                        selRows = pages[pageId];
                        var index = selRows.indexOf(rowid)
                        if (index != -1) {
                            pages[pageId].splice(index, 1);
                        }
                    }
                },

loadComplete: function() {
                if (pages[$('#grdApplications').getGridParam('page')] != null) {
                    var selRows = pages[$('#grdApplications').getGridParam('page')];
                    var i;
                    var limit = selRows.length;
                    for (i = 0; i < limit; i++) {
                        $('#grdApplications').setSelection(selRows[i], true);
                    }
                }
            },
Dave Swersky
A: 

Thank you Dave, I've been googling bout it. But how do you get all checked row data, I mean when I try to get the data with jqGrid('getGridParam','selarrrow') I just get row id from the page that is showing. Help me please. Sorry for my bad english.

Noor