Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We have solved this same problem with subgrids, and the solution may be adaptable to a grouping scenario. We used <a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3acustom_formatter" rel="nofollow">custom formatters</a> to add styling and data attributes for both the header link/checkbox and the subgrid checkboxes. Then we have a link or checkbox in the header row with an event on it that uses jQuery to select all the checkboxes in the subgrid with the appropriate data attribute and style. Finally, the grid load complete event adds the click event handler for the "check all" link.</p> <p>Here's an example custom formatter for the subgrid checkbox column. Note the data-groupingId attribute which stores a value that is used to relate the header row to the subgrid rows.</p> <pre><code>function checkBoxColumnFormatter(cellvalue, options, rowObject) { return "&lt;input type=\"checkbox\"" + data-groupingId=\"" + rowObject.GroupingId + "\" class=\"subgridCheck\" /&gt;"; } </code></pre> <p>Here's an example custom formatter for the "check all" column. Note the data-groupingId attribute which stores a value that is used to relate the header row to the subgrid rows.</p> <pre><code>function checkAllColumnFormatter(cellValue, options, rowObject) { var link = $("&lt;a class=\"checkAll\" href=\"#\" data-groupingId=\"" + rowObject.Id + "\"&gt;Check All&lt;/a&gt;"); var linkHtml = $("&lt;div&gt;").append(link.clone()).remove().html(); return linkHtml; } </code></pre> <p>Here's the load completion event that hooks up the click events for the "check all" links created in the above formatter.</p> <pre><code>function mainGridLoadComplete(data) { $(".checkAll").click(function (e) { checkSubGridRows( $(this).attr("data-groupingId")); // Use the data attribute to specify the value that will be on all the *relevant* subgrid checkboxes. }); }, </code></pre> <p>And finally, here's the method that does the work.</p> <pre><code>function checkSubGridRows(groupingId) { $("#GridId .subgridCheck[data-groupingId=\"" + groupingId + "\"]").not(":disabled").each( function () { $(this).attr("checked", "checked"); }); } </code></pre> <p>This has worked very well for us. All things considered, when things get to be complicated like this, I'd rather have a client-side model to receive data from the JSON web service and be the authoritative source for the jqGrid. I think this would ultimately be preferable to having the jqGrid grab the data itself and swallow the actual data objects, which makes it difficult or impossible to get at the data directly for reference or processing. However, creating and managing a client-side model/view separation is not a trivial undertaking. So this works as a quick alternative. But beware, because this can get out of hand FAST.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload