Original address: http://my.oschina.net/meSpace/blog/41463
Http://www.easyui.net/2010/06/easyui-tutorial-get-selected-row-data-from-datagrid/
Http://easyui.btboys.com/api/easyui API
http://www.iteye.com/problems/47234
jquery Easyui the width of the DataGrid can be set as a percentage.
The data table component contains two methods to get the data for the selected row:
- GetSelected: Gets the data for the first selected row, or returns a blank if no row is selected, otherwise returns the record of the row
- Getselections: Gets all the selected rows of data, returns the array, whose elements are rows of records
Create a label
<table id= "tt" ></table>
Create a data table
$ (' #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 examples
Get the data for the selected row:
var row = $ (' #tt '). DataGrid (' getselected '); if (row) { alert (' Item ID: ' +row.itemid+ ' \nprice: "+row.listprice);}
Gets the item ID for 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 '));
Download data Form Instance code: easyui-datagrid-demo.zip
$ (' #tt '). DataGrid ({
Iconcls: ' Icon-save ',
width:1150,
HEIGHT:650,
Nowrap:false,
Striped:true,
IDfield: ' g_id ',
Collapsible:true,
URL: ' <%=path%>/gamemanage!upload.action ',
Remotesort:false,
IDfield: ' g_id ',
Pagesize:5,
frozencolumns:[[
{field: ' CK ', checkbox:true}
]],
columns:[[
{title: ' Game id ', field: ' g_id ', width:80},
{title: ' Game Name ', field: ' G_name ', width:80},
{title: ' Version ', field: ' G_version ', width:80},
{title: ' Number of players ', field: ' G_players ', width:80},
{title: ' Introduction to the Game ', field: ' G_desc ', width:80},
{title: ' Star ', field: ' G_star ', width:80},
{title: ' Game icon path ', field: ' G_imagepath ', width:80},
{title: ' Game icon name ', field: ' G_imagename ', width:80},
{title: ' Available state ', field: ' G_status ', width:80},
{title: ' Game online time ', field: ' G_onlinetime ', width:80},
{title: ' Support client ', field: ' G_isclient ', width:80},
{title: ' Game Save path ', field: ' G_gamepath ', width:80},
{title: ' Game filename ', field: ' G_gamename ', width:80},
{title: ' Game Key ', field: ' G_key ', width:80},
{title: ' Game Maker ID ', field: ' gc_id ', width:80},
{title: ' Game Type id ', field: ' g_type_id ', width:80},
{title: ' File Size ', field: ' G_filesize ', width:80},
{title: ' Game File path ', field: ' G_packagepath ', width:80}
]],
Pagination:true,
Rownumbers:true
});
Page out
var p = $ (' #test '). DataGrid (' Getpager ');
$ (P). Pagination ({
Onbeforerefresh:function () {
Alert (' before Refresh ');
}
});
Gets the number of rows getselections
Get the number of rows content getselected
var ids = [];
var rows = $ (' #tt '). DataGrid (' Getselections ');
for (var i=0; i<rows.length; i++) {
Ids.push (rows[i].g_id);
}
alert (rows.length);
alert (IDs);
Only delete rows in the page cannot operate on the database ...
Function del () {
var rows = $ (' #tt '). DataGrid ("Getselections"); Get all the rows you select
Loops the selected row
for (var i =0;i<rows.length;i++) {
var index = $ (' #tt '). DataGrid (' Getrowindex ', rows[i]);//Gets the line number of a row
$ (' #tt '). DataGrid (' DeleteRow ', index); Remove the row by line number
}
}
Gets the ID and number of the selected row in the page
function Getselectedarr () {
var ids = [];
var rows = $ (' #tt '). DataGrid (' Getselections ');
for (var i=0; i<rows.length; i++) {
Ids.push (rows[i].g_id);
}
return IDs;
}
var arr = Getselectedarr ();
var num = arr.length;
Text input box with date format
<input id= "dd" class= "Easyui-datebox" ></input>
[Go]easyui get data for the selected row in the data table get selected row from ...