jquery easyui datagrid()--数据网格操作(二)(--可编辑的数据--)

      function initTable(State,theGroup) {
        $('#dataTable').datagrid({
            url: rootUrl + 'Device/device_info/GetDataList',
            method: 'POST',
            queryParams: { 'State': State,'GroupName': theGroup},//-------提交参数
            idField: 'Id',
            fit: true,
            fitColumns: true,
            scrollbarSize:0,//------数据不多时内容整合去除多余留白
            singleSelect: false,
            selectOnCheck: false,//------选中复选框选中行,样式不好看丑,需要自定义样式
            checkOnSelect: true,//-----单击行选中复选框效果,如果js引用冲突没有效果需要写单击行事件(onClickRow())
            //sortName: 'Id',
            //sortOrder: 'asc',
            //rownumbers: true,
            pagination: true,
            pageSize: 10,
            //nowrap: false,
            pageList: [10, 20, 30, 50, 100, 150, 200],//------分页参数每页显示多少条参数必须设置自定义须写入js对象
            //showFooter: true,
            columns: [[
                { title: 'ck', field: 'ck', checkbox: true },
                { title: 'xxxx', field: 'Id', width: 200,hidden:'true'},
                { title: 'xxxx', field: 'Device_Name', width: 200 },
                { title: 'xxxx', field: 'Device_Ordernum', width: 200 },
                {
                    title: 'xxxx', field: '__', width: 60, fixed: true,align:'center',formatter: function (value, row) {
                        var html = '';
               ....return html;
                    }
                }
            ]],
            onBeforeLoad: function (param) {
            },
       //-------关键操作(一、打开可编辑状态)--------// onDblClickCell:
function (index, field) { if (editIndex != index) { if (endEditing()) { $('#dataTable').datagrid('selectRow', index).datagrid('beginEdit', index); editIndex = index; var ed = $('#dataTable').datagrid('getEditor', { index: index, field: field }); if (ed) { $(ed.target).combobox({ onLoadSuccess: function () { var theId = $(ed.target).combobox('getData').find(function (item) { if (item.G_State == "是") return item }); $(ed.target).combobox('select', theId.Id); }, onChange: function () { }, }) } } else { setTimeout(function () { $('#dataTable').datagrid('selectRow', editIndex); }, 0); } } },
       //------关键操作(二、结束编写时返回的值)-----//  onEndEdit:
function (index, row) { var ed = $('#dataTable').datagrid('getEditor', { index: index, field: 'GroupName', }); row.GroupId = $(ed.target).combobox('getValue'); row.GroupName = $(ed.target).combobox('getText'); } }); }
//------需要引用的参数------//    
  var editIndex = undefined;       function endEditing() {       if (editIndex == undefined) { return true }       f ($('#dataTable').datagrid('validateRow', editIndex)) {       $('#dataTable').datagrid('endEdit', editIndex);         editIndex = undefined;       return true;       } else {         return false;         }       }
 

猜你喜欢

转载自www.cnblogs.com/zxy-room/p/12501966.html