$('#tb-datagrid').datagrid({ title: '待分配库位', iconCls: 'icon-search', width: 1112, height: 500, rownumbers: true, idField: 'ID', sortOrder: 'desc', sortName: 'ID', remoteSort: false, nowrap: false, collapsible: true, striped: true, fitColumns: false, pagesize: 10, pagination: true, url: '/StockOut/WebAjax/ProcCheckOutList.ashx', queryParams: convertArray($('#fmSearch').serializeArray()), onLoadSuccess: function (data) { $('#tbCheckOut').datagrid('collapseGroup'); //设置折叠 }, onDblClickCell: function (index, field, value) { }, columns: [[ { field: 'singlechk', width: 50, checkbox: true}, { field: 'CheckOutType', title: '单据类型', width: 80, align: 'center', sortable: true, formatter: function (value, row) { return FGetCheckOutTypeInfo(value); } }, { field: 'PostTime', title: '下单日期', width: 70, align: 'center', sortable: true, formatter: function (value, row) { return ChangeShortDateFormat(value); } }, { field: 'K3OrderCode', title: '编号', width: 120, align: 'center', sortable: true }, { field: 'SerialNo', title: '流水号', width: 120, align: 'center', sortable: true }, { field: 'CustomName', title: '客户', width: 200, align: 'center', sortable: true, formatter: function (value, row) { var rtnStr = value; //todo 截取 return rtnStr; } }, { field: 'ItemSNCode', title: '物料编码', width: 120, align: 'center', sortable: true }, { field: 'SKUCode', title: 'SKU', width: 50, align: 'center', sortable: true }, { field: 'ItemSNName', title: '物料名称', width: 250, align: 'center', sortable: true }, { field: 'AssignNum', title: '计划', width: 50, align: 'center', sortable: true }, { field: 'ActualNum', title: '实际', width: 50, align: 'center', sortable: true }, { field: 'HasAllotedNum', title: '已分配', width: 50, align: 'center', sortable: true }, { field: 'UnitName', title: '单位', width: 50, align: 'center', sortable: true }, { field: 'SpecificationsName', title: '规格型号', width: 60, align: 'center', sortable: true }, { field: 'WarehouseName', title: '发货仓库', width: 100, align: 'center', sortable: true }, { field: 'ChannelName', title: '渠道', width: 30, align: 'center', sortable: true }, { field: 'ID', title: '操作', width: 120, align: 'center', formatter: function (value, row) { var rtnStr = ""; if (row.Status == 0) { rtnStr = '<a href="javascript:void()" class="gridAColor" onclick="FProcTask(1,' + value + ')">自动出库</a> <a href="javascript:void()" onclick="FProcTask(0,' + value + ')" class="gridAColor" >手动出库</a>'; } return rtnStr; } } ]], groupField: 'K3OrderCode', view: groupview, groupFormatter: function (value, rows) { var rtnStr = ""; rtnStr += '<input type="checkbox" onclick="FGPCkbClick(this)" helpGPVal="' + value + '" name="gpChk" />'; rtnStr += value + ' 单据数量=' + rows.length + '条'; var sumAssignNum = 0; var sumActualNum = 0; for (var i = 0; i < rows.length; i++) { sumAssignNum += rows[i].AssignNum; sumActualNum += rows[i].ActualNum; } rtnStr += " 计划量=" + sumAssignNum; rtnStr += " 实际量=" + sumActualNum; return rtnStr; } });
下面是实现该功能的js,部分有修改:
//分组ckb事件 function FGPCkbClick(obj) { var gpVal = $(obj).attr("helpGPVal"); - var isChecked = $(obj).attr('checked') == 'checked' ? true : false; + var isChecked = $(obj).is(":checked"); selectByGroup(isChecked, gpVal, '#tb-datagrid'); } //分组选中 function selectByGroup(checked, value, tableIdSelector) { var groups = $(tableIdSelector).datagrid("options").view.groups; var rows; for (var i = 0; i < groups.length; i++) { if (groups[i].value == value) { rows = groups[i].rows; break; } } if (checked) { for (var i = 0; i < rows.length; i++) { $(tableIdSelector).datagrid("selectRow", $(tableIdSelector).datagrid("getRowIndex", rows[i])); } } else { for (var i = 0; i < rows.length; i++) { $(tableIdSelector).datagrid("unselectRow", $(tableIdSelector).datagrid("getRowIndex", rows[i])); } } } //datagrid顶部ckb事件 function BoundCkbAllClick() { $('.datagrid-header-check input').click(function () { - var isChecked = $(this).attr('checked'); + var isChecked = $(this).is(':checked');//返回true or false $('input[name="gpChk"]').each(function (index, elemetn) { //alert('90:' + $(this).attr('helpgpval')); - if (isChecked == 'checked') { - $(this).attr('checked', isChecked); - } else { - $(this).removeAttr('checked'); - } + $(this).prop('checked', isChecked); }); }); }