Easyui的 datagrid getSelections只能获取表格中的一行数据

错误原因:

  var rows = $("#List").datagrid("getSelections");
  alert(rows.length)

取出来的的数据长度为一条

解决方案:

datagrid属性:idField: 'id',//必须要写

并且必须要是你数据中的id列名,改好即可获取多条数据。

  $('#List').datagrid({
            url: '/User/GetList',
            method: 'post',
            fitColumns: true,
            sortName: 'id',
            sortOrder: 'asc',
            idField: 'id',//这里修改
            striped: true,
            singleSelect: false,
            rownumbers: true,
            pageSize: 10,
            pageList: [10, 20, 30, 40, 50],
            pagination:true,
            columns: [[
                {field:'ck',checkbox:true},
                { field: 'id', title: 'ID', width: 10, align: 'center',sortable:true },
                 {
                     field: 'email', title: '注册邮箱', width: 20, align: 'center',sortable:true,
                     formatter: function (val) {
                         return '' + val + '';
                     }
                 },
                  { field: 'pwd', title: '密码', width: 20, align: 'center' },
                   { field: 'logintime', title: '登录时间', width: 20, align: 'center', sortable: true, formatter: formatDate },

            ]],
           toolbar: '#tb'

        });





你可能感兴趣的:(Easyui,JavaScript)