$("#gridTable").on("change", "input[type=checkbox]", function (e) { var currentCB = $(this); var grid = jQuery('#gridTable'); var isChecked = this.checked; if (currentCB.is(".groupHeader")) { //if group header is checked, to check all child checkboxes var checkboxes = currentCB.closest('tr').nextUntil('tr.gridTableghead_0').find('.cbox[type="checkbox"]'); checkboxes.each(function () { if (!this.checked || !isChecked) grid.setSelection($(this).closest('tr').attr('id'), true); }); } else { //when child checkbox is checked var allCbs = currentCB.closest('tr').prevAll("tr.gridghead_0:first").nextUntil('tr.gridghead_0').andSelf().find('[type="checkbox"]'); var allSlaves = allCbs.filter('.cbox'); var headerCB = allCbs.filter(".groupHeader"); var allChecked = !isChecked ? false : allSlaves.filter(":checked").length === allSlaves.length; headerCB.prop("checked", allChecked); } });
groupText: ['<input type="checkbox" class="groupHeader" style="top:3px"/>' {1} </span>条 '],