带有复选框的jqGrid TreeGrid,签入父级,标记所有子复选框

时间:2012-11-22 22:26:33

标签: jqgrid treegrid

我有一个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',

    });
});

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

和CLUE:首先加载所有复选框都已选中,没关系,我尝试通过点击父级“取消检查”孩子

    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 Controller的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(data,JsonRequestBehavior.AllowGet);

0 个答案:

没有答案