I have jqGrid with a column that contains a checkbox. I've noticed that when the user toggles the checkbox, jqGrid doesn't actually put the row into edit mode. So when the user clicks the save button the new value of the checkbox is not saved.
Is this the default behavior for checkboxes in jgGrid? What't the best way to make jqGrid saved the checkbox value?
Here is the jqGrid code:
var myGrid = jQuery("#myGrid");
myGrid.jqGrid({
editurl: 'UpdateData',
datatype: function (postdata) {
//some code
},
height: "450",
footerrow: false,
userDataOnFooter: false,
autowidth: true,
viewrecords: true,
rowNum: 100,
rowList: [25, 50, 100, 200, 300, 400, 500, 1000],
sortname: 'SomeId',
pager: '#footer',
caption: "",
colNames: ['Field1', 'Field2'],
colModel: [
{ name: 'Col1', index: 'Col1', hidden: false, editable: true, sortable: true, search: true },
{ name: 'MyCheckBox', index: 'MyCheckBox', hidden: false, editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", formatoptions: { disabled: false }, search: true }
],
onSelectRow: function (index) {
myGrid.jqGrid('editRow', index, true);
}
});
myGrid.jqGrid('navGrid', '#footer',
{ edit: false, add: false, del: false, search: false },
{ closeAfterAdd: true }, // use default settings for edit
{ closeAfterAdd: true, left: ((document.body.clientWidth / 2) - 100), top: ((document.body.clientHeight / 2) - 50) }, // use default settings for add
{ }, // delete instead that del:false we need this
{ multipleSearch: false }, // enable the advanced searching
{ closeOnEscape: true} /* allow the view dialog to be closed when user press ESC key*/
);
myGrid.jqGrid('navButtonAdd', '#footer',
{
buttonicon: "none",
caption: "Save",
onClickButton: function () {
//save the currently selected row
}
})
I was thinking about using jQuery to attach a "change" handler to each checkbox that would put that row into edit mode when the user clicked the checkbox. Seems like a hack though and I wasn't sure how to properly identify the checkbox column in the grid (my example only shows one checkbox but the grid actually has two).
Does jqGrid support better checkbox behavior than this?