2

我在父节点和子节点中有一个带有复选框的 TreeGrid。选中父节点中的复选框应标记子节点中的所有复选框。我的 TreeGrid 工作正常,我尝试将事件仅绑定到自定义格式化程序中的父节点。它也奏效了。后来我尝试标记子节点但没有效果。子节点的复选框保持不变。请帮忙!

    $(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',

    });
});

格式化程序和取消格式化:

    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';
    }

和线索:首先加载所有复选框都被选中,没关系,我尝试通过单击父级来“取消选中”子级

    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)


        }
    }

我来自 MVC 控制器的 JSON:

    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()

};

返回 Json(数据,JsonRequestBehavior.AllowGet);

4

0 回答 0