I have a TreeGrid with checkboxes in both parent and child nodes. Checking a checkbox in parent node should mark all checkboxes in child nodes. My TreeGrid works ok, I tried to bind an event only to parent node in a custom formatter. It also worked. Later on I tried to mark child nodes but with no effect. Child nodes' checkboxes remain unchanged. Please help!
$(document).ready(function () {
jQuery("#list2").jqGrid({
url: '@Url.Action(some action it is ok)
mtype: 'GET',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
datatype: "json",
colNames: ['id', 'Data', 'Typ', 'Liczba dni', 'Liczba godzin', 'Zatwierdzalny', 'Anulowalny', 'Zatwierdz', 'Anuluj'],
colModel: [
{ name: 'id', index: 'id', hidden: true },
{ name: 'data', index: 'data' },
{ name: 'typ', index: 'typ' },
{ name: 'ileDni', index: 'ileDni' },
{ name: 'ileGodzin', index: 'ileGodzin' },
{ name: 'zatwierdzalny', index: 'zatwierdzalny'},
{ name: 'anulowalny', index: 'anulowalny', hidden: true },
// { name: 'zatwierdz', index: 'zatwierdz',
// editable: true, edittype: 'checkbox',editoptions: { value: "True:False" },
// formatter: "checkbox", formatoptions: { disabled: false }
// },
{ name: 'zatwierdz', index: 'zatwierdz', edittype: 'checkbox', editoptions: { value: "True:False" },
editable: true, formatter: cboxFormatter, unformat: cboxUnFormatter
},
{ name: 'anuluj', index: 'anuluj',
editable: true, edittype: 'checkbox', editoptions: { value: "True:False" },
formatter: "checkbox", formatoptions: { disabled: false }
}
],
rowNum: 50,
height: 'auto',
records: 50,
width: 1050,
sortable: true,
viewrecords: true,
postData: {
rok: function () {
return $("#lata option:selected").val();
}
},
treeGrid: true,
treeGridModel: "adjacency",
ExpandColumn: 'data',
treeIcons: { leaf: 'ui-icon-document' },
// editurl: 'edit url',
});
});
formatter and unformat:
function cboxFormatter(cellvalue, options, rowObject) {
if (rowObject[11] == "true") { //isChild - how else can I check this?
return '<input type="checkbox"' + (cellvalue ? ' checked="checked"' : '') + '/>';
}
else {
return '<input type="checkbox"' + (cellvalue ? ' checked="checked"' : '') +
'onclick="zaznacz(' + options.rowId + ')" />';
}
}
function cboxUnFormatter(cellvalue, options, cell) {
return $('input', cell).attr("checked") ? 'True' : 'False';
}
and the CLUE: at first load all checkboxes are checked, it is ok, I try to "un-check" child by clicking parent
function zaznacz(e) {
var localRow = $('#list2').jqGrid('getLocalRow', e),
children = $('#list2').jqGrid('getNodeChildren', localRow);
var Row = $('#list2').jqGrid('getRowData', e);
for (i = 0; i < children.length; i++) {
//alert(children[i].id); OK
//$('#list2').jqGrid('setCell', children[i].id, 'zatwierdz', "False");
$('#list2').jqGrid('getLocalRow', children[i].id).zatwierdz = "False";
//localRow.zatwierdz = 'False';
alert($('#list2').jqGrid('getLocalRow', children[i].id).zatwierdz);
NO EFFECT AT ALL! even if I do:
alert($('#list2').jqGrid('getLocalRow',children[i].id).zatwierdz);
alert is OK, "False" is printed, but checkbox reamins checked (unchanged)
}
}
my JSON from MVC Controller:
var data = new
{
rows = (
from du in dni
select new
{
cell = new string[] {
du.id,
du.data,
du.typ,
du.ileDni,
du.ileGodzin,
du.zatwierdzalny,
du.anulowalny,
du.zatwierdz,
du.anuluj,
du.level,
du.parent,
du.isLeaf ? "true":"false",
du.expanded ? "true":"false",
du.loaded ? "true":"false"
}
}).ToArray()
};
return Json(data, JsonRequestBehavior.AllowGet);