I have a jqGrid table with multi-select checkboxes that I have customized with CSS and prettyCheckable.
To customize all the checkboxes of my table I set
First of all I find integration of other plugins in jqGrid interesting. I didn't used prettyCheckable before. After same analyse of the way how prettyCheckable
works I created the demo which demonstrate an example of such integration. The results look like on the picture below
To understand the code one should understand that prettyCheckable
convert original HTML fragment of the cell with multiselect checkbox
in more complex structure
I find not good that prettyCheckable
always create empty <label>
element which increase the height of the column. So I added the code which make all the <label>
element hidden.
The next problem is that prettyCheckable
uses <a>
element with optional class "checked"
for chechboxes and inform the original checkbox (which are hidden after initialization prettyCheckable
) per change
event, but jqGrid wait for click
event on the row or on the checkbox and have no reaction on change
event.
I skip some less interesting technical details now. The most important parts of the code of the demo you find below
$("#list").jqGrid({
...
multiselect: true,
multiselectWidth: 28,
onSelectAll: function (aRowids, status) {
var i, l = aRowids.length, $a,
selector = "#jqg_" + $.jgrid.jqID(this.id) + "_";
for (i = 0; i < l; i++) {
$a = $(selector + $.jgrid.jqID(aRowids[i])).next("a");
if (status) {
$a.addClass("checked");
} else {
$a.removeClass("checked");
}
}
},
beforeSelectRow: function (rowid, e) {
if (e.target.nodeName.toUpperCase() === "A" &&
$(e.target).prev("input").hasClass("cbox")) {
$(e.target).prev("input").click();
}
return true;
},
onSelectRow: function (rowid, state) {
var $a = $("#jqg_" + $.jgrid.jqID(this.id + "_" + rowid)).next("a");
if (state) {
$a.addClass("checked");
} else {
$a.removeClass("checked");
}
},
loadComplete: function () {
var $checkboxes = $(this).find("input.cbox");
$checkboxes.prettyCheckable();
$checkboxes.siblings("label").hide();
}
});
$("#cb_" + $.jgrid.jqID($grid[0].id)).change(function() {
$(this).triggerHandler("click");
}).prettyCheckable();
$("#cb_" + $.jgrid.jqID($grid[0].id)).siblings("label").hide();
I used additional CSS settings (see the answer) to increase the height of the column headers
th.ui-th-column div {
white-space: normal !important;
height: auto !important;
}