Dan
Dan

Reputation: 724

Saving selected rows in a jqGrid while paging

I have a jqGrid with which users will select records. A large number of records could be selected across multiple pages.

The selected rows seem to get cleared out when the user pages through the data. Is it up to the developer to manually track the selected rows in an array? I'm fine doing this, but I'm not sure what the best way is. I'm not sure I want to be splicing an array whenever any number of records are selected as that seems like it could really slow things down.

My end goal is to have a jQueryUI dialog that, when closed, while store all the selected rows so I can post it to the server.

Note: added aspnetmvc tag only because this is for an MVC app.

Upvotes: 4

Views: 4577

Answers (3)

Paul
Paul

Reputation: 3954

I had a similar requirement and came across this post. I thought I'd share my solution:

var selId;
$("#grid").jqGrid({
    ...
    onSelectRow: function(id){ 
        selId = id;
    },
    gridComplete: function() {
        $("#grid").setSelection(selId, true); 
    },
    ...
});

This was for one selection only, but could easily be adapted to multiple selections by making selId an array.

Upvotes: 1

Jeremy B.
Jeremy B.

Reputation: 9216

I would load each row when selected into the $.data() container. This way you can store them away from the grid and when the user is done selecting have a nice packaged data set you can then work with.

Upvotes: 1

Craig Stuntz
Craig Stuntz

Reputation: 126577

Yes, it's up to the developer to track this selection manually. You don't have to use an array, though; you can use any data structure you like.

Upvotes: 1

Related Questions