I'm quite the beginner in jQuery and I'm trying to get a simple columnChooser to work for jqGrid. I'm using jqGrid's navigation bar to insert an "Add/remove columns" button, and on the click event of this button I display the column chooser. Having loaded the multiselect plugin before, it uses it to display the columns with checkboxes.
Here is my code:
$("#myGrid")
.jqGrid({
...
toppager: true,
pager: jQuery('#myPager'),
...
})
.jqGrid('navGrid', "#myPager", { //add the navigator (defaults to the bottom of the grid)
edit: false, add: false, del: false, search: false, refresh: false, //remove all default buttons
cloneToTop: true //clone it, so a new one is created on top of the grid (name of the clone is <id of grid>_toppager)
})
.jqGrid('navButtonAdd', "#myGrid_toppager", { //add a custom button to the cloned navigator
caption: "show/hide columns",
onClickButton: function () {
var colChooser = $("#colchooser_myGrid");
if (colChooser.length == 0) {
$("#myGrid").jqGrid('columnChooser', {
width: 260,
height: 220,
classname: "column-chooser",
msel_opts: {
autoOpen: true,
header: false,
height: "auto",
classes: "column-chooser" },
dlog_opts: { modal: true, resizable: false }
});
}
else {
// ??
}
}
});
And my CSS:
.column-chooser .ui-multiselect-checkboxes {
overflow-y: hidden;
}
I am stuck with three things:
- the buttons (OK and Cancel) are not visible. I don't find them anywhere on the inner html code. When I remove the options, they appear, but the multiselect does not resize to fit the columnChooser dialog.
- how do I get the multiselect to be "unclosable"? I tried adding
beforeclose: function () { return false; }
in the msel_opts object, and it works, but then the multiselect values stay visible always, even when closing the dialog. - the dialog only displays once, then refuse tho whow up again. It seems it's because it has been created, but it seems the jqGrid calls destroy on both the dialog and the multiselect, so I cannot show them again.
I am using jquery 1.4.4, jquery-ui 1.8.18, jqgrid 4.3.1 and multiselect 1.12, all tested under Firefox 11.