1

I have JQGrid loading data from WCF OperationContract with paging and sorting working fine. I am using "multiselect: true" so that I get the checkbox column and ability to select multiple rows. I've implemented gridComplete:, onSelectAll: and onSelectRow: to capture when checkboxes are checked/unchecked and to maintain checked state upon pagination. I am able to save the checkbox state to the DB via another WCF method call.

What I cannot figure out how to do is load the saved checkbox state for each row along with the other fields specified in colModel:.

Any ideas? I realize I can make a separate WCF service call to get the values, loop through them and set state manually, but that seems like a huge waste and overly clunky.

Thanks in advance.

RadiusMaximus
  • 11
  • 1
  • 3

1 Answers1

0

The simplest way, which I imagine me immediately after reading of your question, is to have additional hidden column (hidden: true property in the colModel for the column) and the checkboxes inside. You can load the selection state from the database an fill the hidden checkboxes. Inside of loadComplete or gridComplete you can use the information to select the rows.

If you would use loadComplete instead of gridComplete you can even eliminate the need to hold hidden row. The callback method loadComplete has data parameter which are initialized with the data originated from the ajax call. So if your server response contain more information as jqGrid need the data will be ignored by jqGrid, but you can see the data in the loadComplete and use the information to set row selection.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg! I think I will try loadComplete and manually set with the data param, so I don't have to create an additional, hidden column, since I already have it working with multiselect: true. It would be nice however, if the the checkbox field added by multiselect could automatically be bound like the rest of the fields. Thanks! – RadiusMaximus Sep 16 '11 at 21:06
  • @RadiusMaximus: Look at [the answer](http://stackoverflow.com/questions/6575192/jqgrid-change-background-color-of-row-based-on-row-cell-value-by-column-name/6575634#6575634) and [this one](http://stackoverflow.com/questions/7080859/jqgrid-iterate-over-the-grid-data-in-a-subgrid/7084920#7084920) which show how to enumerate the rows and do some action in every row. [Another answer](http://stackoverflow.com/questions/3564898/jqgrid-programatically-select-grid-row/3571392#3571392) do close work as you need. The usage of [jQuery.inArray](http://api.jquery.com/jQuery.inArray/) can be also helpful. – Oleg Sep 16 '11 at 21:20
  • I can't use loadComplete. it's not being called because I do this: datatype: function (pdata) { beginGridRequest('Retailers'); getRetailerData(pdata) }, – RadiusMaximus Sep 16 '11 at 22:12
  • I posed new question about loadComplete not firing: http://stackoverflow.com/questions/7451198/jqgrid-loadcomplete-not-firing-when-datatype-function – RadiusMaximus Sep 16 '11 at 23:03