表格
<c:datagrid class="easyui-datagrid" pageSize="10" pageList="15,30,50,100" pagination="false"
url=""
id="leftGrid" remoteSort="true" fitColumns="true" fit = "true" singleSelect="false" border="" style="height:550px;width:100%"
frozenColumns="[[{title:'UUID', field:'UUID_ID',checkbox:'true',width:'100px',align:'center'}]]"
>
<thead >
<tr>
<th field="UUID" width="20%" align="center" hidden="hidden">UUID</th>
<th field="STAFF_INFO_NAME" width="20%" align="center" >姓名</th>
<th field="RELATION_TYPE" width="20%" align="center" >主职兼职</th>
<th field="STAFF_PHONE_NO" width="20%" align="center" >手机号码</th>
<th field="POST_NAME" width="40%" align="center" >所在岗位</th>
</tr>
</thead>
</c:datagrid>
//获取选则的数据
var selected = $("#leftGrid").datagrid("getChecked");//获取的是数组,多行数据
//通过循环选中的数据,对数据进行想要的操作
if(selected.length>0) {
for (var i = 0; i < selected.length; i++) {
if (selected[i].CHECK_STATUS == '2') { //审核中的数据不允许操作
layer.alert("状态为2的不允许操作!", {icon: 2});
} else {
$('#rightGrid').datagrid('appendRow', selected[i]);//把选择的数据添加到右侧grid
var rowIdex = $('#leftGrid').datagrid("getRowIndex", selected[i]);//得到索引
$('#leftGrid').datagrid("deleteRow", rowIdex);//删除左侧grid中被移动的数据
}
}
}else{
layer.alert("请选择数据!", {icon: 2});
}
getSelected:取得第一个选中行数据,如果没有选中行,则返回 null,否则返回记录。
getSelections:取得所有选中行数据,返回元素记录的数组数据。
getChecked:取得checkbox选择行的数据,返回元素记录的数组数据。
getSelected跟getSelections是选中行,而且getChecked是选择行。
选中行的意思就是,我们单击到某一个行,这个时候该行的背景色为黄色,就证明我们选中了该行。
选择行的意思就是,我们在改行放置了一个checkbox按钮,我勾选了这个按钮,因此也可以将选择行称为勾选行更贴切一些!
如果选中了多行而只获得一行,则可能是datagrid的idField属性值设置错误导致的,可修改正确或者去掉。