In the use of easyui getselections and getselected, if you do not pay attention to the use of these two attributes, It is very troublesome to locate the problem if you do not know the two attributes. Make a record of the detour.
The DataGrid component contains two methods to retrieve selected row data:
· Getselected: Get the data of the first selected row. If no row is selected, null is returned. Otherwise, this record is returned.
· Getselections: obtains the data of all selected rows. If the element is a record, array data is returned.
Create tag
<table id="tt"></table>
Create a DataGrid
$(‘#tt‘).datagrid({ title:‘Load Data‘, iconCls:‘icon-save‘, width:600, height:250, url:‘datagrid_data.json‘, columns:[[ {field:‘itemid‘,title:‘Item ID‘,width:80}, {field:‘productid‘,title:‘Product ID‘,width:80}, {field:‘listprice‘,title:‘List Price‘,width:80,align:‘right‘}, {field:‘unitcost‘,title:‘Unit Cost‘,width:80,align:‘right‘}, {field:‘attr1‘,title:‘Attribute‘,width:100}, {field:‘status‘,title:‘Status‘,width:60} ]]});
Usage demonstration
Get the selected row data:
var row = $(‘#tt‘).datagrid(‘getSelected‘);if (row){ alert(‘Item ID:‘+row.itemid+"\nPrice:"+row.listprice);}
Get the Itemid of all selected rows:
var ids = [];var rows = $(‘#tt‘).datagrid(‘getSelections‘);for(var i=0; i<rows.length; i++){ ids.push(rows[i].itemid);}alert(ids.join(‘\n‘));
Note: If you should actually use VaR rows =$ ('# tt '). dataGrid ('getselections'); but var ROW = $ ('# tt') is used by mistake '). dataGrid ('getselected'); The retrieved row. length is a null value. Very depressing!