EasyUI 取得选中行数据

本文介绍EasyUI框架下DataGrid组件如何通过getSelected和getSelections方法获取选中行的数据,包括单行数据及所有选中行的itemid,适用于网页应用的数据操作场景。

转自:http://www.jeasyui.net/tutorial/23.html

本实例演示如何取得选中行数据。

数据网格(datagrid)组件包含两种方法来检索选中行数据:

  • getSelected:取得第一个选中行数据,如果没有选中行,则返回 null,否则返回记录。
  • getSelections:取得所有选中行数据,返回元素记录的数组数据。
创建数据网格(DataGrid)
  1. <table id="tt" class="easyui-datagrid" style="width:600px;height:250px"
  2. url="data/datagrid_data.json"
  3. title="Load Data" iconCls="icon-save">
  4. <thead>
  5. <tr>
  6. <th field="itemid" width="80">Item ID</th>
  7. <th field="productid" width="80">Product ID</th>
  8. <th field="listprice" width="80" align="right">List Price</th>
  9. <th field="unitcost" width="80" align="right">Unit Cost</th>
  10. <th field="attr1" width="150">Attribute</th>
  11. <th field="status" width="60" align="center">Stauts</th>
  12. </tr>
  13. </thead>
  14. </table>
使用演示

取得选中行数据:

  1. var row = $('#tt').datagrid('getSelected');
  2. if (row){
  3. alert('Item ID:'+row.itemid+"
  4. Price:"+row.listprice);
  5. }

取得所有选中行的 itemid:

  1. var ids = [];
  2. var rows = $('#tt').datagrid('getSelections');
  3. for(var i=0; i<rows.length; i++){
  4. ids.push(rows[i].itemid);
  5. }
  6. alert(ids.join('
  7. '));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值