要求:动态加载;级联勾选;通关类型判断显示包库/还是镜像(列有所不同,镜像共4列),勾选一个复选框,后面的复选框变为不可勾选状态。
下面是具体代码:
1,初始化treegrid,(其中有几个type列,是由后台人员提供的字段名,虽然我也不想弄一堆type...汗)
var root = 20543; //初始化产品树 function InitProductTreeGrid(rootid) { var type = '<%=Controler.ProductType%>'; var ishowPack = true; var ishowMirro = true; //1,包库;2,镜像 if (type == '1') { ishowPack = false; ishowMirro = true; } else { ishowPack = true; ishowMirro = false; }; $('#tt_Product').treegrid({ url: '../Handlers/Contract_ProductHandler.ashx', queryParams: { handlertype: "InitProductTreeGrid", ContractId: $('#ContractId').val(), CatalogId: rootid, pindex: $('#pindex').val() }, idField: 'id', width: 930, treeField: 'CatalogName', fitColumns: true, //宽度自适应窗口 rownumbers: false, //是否加行号 singleSelect: true, scrollbarSize: 0, //去除滚动条,否则右边最后一列会自动多处一块 columns: [[ { title: '产品列表', field: 'CatalogName', width: 210 }, { title: '产品ID', field: 'CatalogId', hidden: true }, { title: '父产品ID', field: 'ParentId', hidden: true }, { title: '父产品名称', field: 'ParentName', hidden: true }, { title: '产品类型', field: 'ProductType', hidden: true }, { title: '是否为子节点', field: 'isLeaf', hidden: true }, //备注:(1,是;0,否) { title: '是否为父节点', field: 'isParent', hidden: true }, { title: 'IsChecked', field: 'IsCheck', hidden: true }, { title: 'CurrentYearPrices', field: 'type1', hidden: true }, { title: 'MirrorCurrentYearPrices', field: 'type3', hidden: true }, { title: 'MirrorEarlyPrices', field: 'type4', hidden: true }, { title: 'MirrorPrevious3YearPrices', field: 'type5', hidden: true }, { field: 'CurrentYearPrices', title: '当前价格', width: 200, hidden: ishowPack, formatter: function (value, rec, index) { var d = '<input type="checkbox" catalogid="' + rec.CatalogId + '" ' + (rec.type1 == 'True' ? 'checked="checked"' : '') + ' parent="CurrentYearPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + (value != 0 ? value.substr(0, value.length - 2) : '0.00'); return d; } }, { field: 'MirrorCurrentYearPrices', title: '当前价格', width: 200, hidden: ishowMirro, formatter: function (value, rec, index) { var d = '<input type="checkbox" catalogid="' + rec.CatalogId + '" ' + (rec.type3 == 'True' ? 'checked="checked"' : '') + ' parent="MirrorCurrentYearPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + value.substr(0, value.length - 2); //var d = '<span>' + value + '</span>'; return d; } }, { field: 'MirrorPrevious3YearPrices', title: '前阶段价格', width: 200, hidden: ishowMirro, formatter: function (value, rec, index) { var d = '<input type="checkbox" catalogid="' + rec.CatalogId + '" ' + (rec.type5 == 'True' ? 'checked="checked"' : '') + ' parent="MirrorPrevious3YearPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + value.substr(0, value.length - 2); return d; } }, { field: 'MirrorEarlyPrices', title: '早期价格', width: 200, hidden: ishowMirro, formatter: function (value, rec, index) { var d = '<input type="checkbox" catalogid="' + rec.CatalogId + '" ' + (rec.type4 == 'True' ? 'checked="checked"' : '') + ' parent="MirrorEarlyPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + value.substr(0, value.length - 2); return d; } }, { field: 'type0', title: '是否赠送', width: 200, formatter: function (value, rec, index) { //alert(rec.isPresent); var d = '<input type="checkbox" catalogid="' + rec.CatalogId + '" ' + (rec.type0 == 'True' ? 'checked="checked"' : '') + ' parent="IsPresent' + rec.ParentId + '" isparent="' + rec.isParent + '" value="0" /> '; return d; } } ]], loadFilter: function (data, parentId) { //逐层加载 function setData() { var todo = []; for (var i = 0; i < data.length; i++) { todo.push(data[i]); } while (todo.length) { var node = todo.shift(); if (node.children) { node.state = 'closed'; node.children1 = node.children; node.children = undefined; todo = todo.concat(node.children1); } } } setData(data); var tg = $(this); var opts = tg.treegrid('options'); opts.onBeforeExpand = function (row) { if (row.children1) { tg.treegrid('append', { parent: row[opts.idField], data: row.children1 }); row.children1 = undefined; tg.treegrid('expand', row[opts.idField]); } return row.children1 == undefined; }; return data; }, onLoadSuccess: function (row, data) { //alert(data[0].CatalogId) RelativeTreeGridCheck(); } }); };
2,onLoadSuccess中的RelativeTreeGridCheck()级联方法