jQuery EasyUI 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

取得选中行数据

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

1.getSelected:取得第一个选中行数据,如果没有选中行,则返回 null,否则返回记录。

2.getSelections:取得所有选中行数据,返回元素记录的数组数据。

如下代码,先创建数据表格,然后取得选中行的数据。

<!--创建表格-->
<table class="easyui-datagrid" title="Basic DataGrid" style="width:600px;height:250px"
            data-options="singleSelect:true,collapsible:true" id='dg'>
        <thead>
            <tr>
                <th data-options="field:'itemid',width:80">Item ID</th>
                <th data-options="field:'productid',width:100">Product</th>
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
                <th data-options="field:'attr1',width:100">Attribute</th>
                <th data-options="field:'status',width:60,align:'center'">Status</th>
            </tr>
        </thead>
    </table>
//取得选择中行
var row = $('#tt').datagrid('getSelected');
    if (row){
        alert('Item ID:'+row.itemid+"\nPrice:"+row.listprice);
    }
//取得所有选中行的itemid
var ids = [];
    var rows = $('#tt').datagrid('getSelections');
    for(var i=0; i<rows.length; i++){
        ids.push(rows[i].itemid);
    }
    alert(ids.join('\n'));
按照上面代码,去试一试吧!