标签:
原文地址: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
数据表格组件包含两个方法来获取选中行的数据:
<table id="tt"></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} ]] });
获取选中行的数据:
var row = $(‘#tt‘).datagrid(‘getSelected‘); if (row){ alert(‘Item ID:‘+row.itemid+"\nPrice:"+row.listprice); }
获取所有选中行的项id:
var ids = []; var rows = $(‘#tt‘).datagrid(‘getSelections‘); for(var i=0; i<rows.length; i++){ ids.push(rows[i].itemid); } alert(ids.join(‘\n‘));
下载数据表格实例代码: 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:‘游戏ID‘,field:‘g_id‘,width:80},
{title:‘游戏名称‘,field:‘g_name‘,width:80},
{title:‘版本‘,field:‘g_version‘,width:80},
{title:‘玩家数量‘,field:‘g_players‘,width:80},
{title:‘游戏简介‘,field:‘g_desc‘,width:80},
{title:‘星级‘,field:‘g_star‘,width:80},
{title:‘游戏图标路径‘,field:‘g_imagepath‘,width:80},
{title:‘游戏图标名称‘,field:‘g_imagename‘,width:80},
{title:‘可用状态‘,field:‘g_status‘,width:80},
{title:‘游戏上线时间‘,field:‘g_onlinetime‘,width:80},
{title:‘是否支持客户端‘,field:‘g_isclient‘,width:80},
{title:‘游戏储存路径‘,field:‘g_gamepath‘,width:80},
{title:‘游戏文件名‘,field:‘g_gamename‘,width:80},
{title:‘游戏密钥‘,field:‘g_key‘,width:80},
{title:‘游戏厂商ID‘,field:‘gc_id‘,width:80},
{title:‘游戏类型ID‘,field:‘g_type_id‘,width:80},
{title:‘文件大小‘,field:‘g_filesize‘,width:80},
{title:‘游戏文件路径‘,field:‘g_packagepath‘,width:80}
]],
pagination:true,
rownumbers:true
});
//分页
var p = $(‘#test‘).datagrid(‘getPager‘);
$(p).pagination({
onBeforeRefresh:function(){
alert(‘before refresh‘);
}
});
//获取行数getSelections
//获取行数内容 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);
//只能在页面中删除行 不能对数据库操作...
function del(){
var rows = $(‘#tt‘).datagrid("getSelections"); //获取你选择的所有行
//循环所选的行
for(var i =0;i<rows.length;i++){
var index = $(‘#tt‘).datagrid(‘getRowIndex‘,rows[i]);//获取某行的行号
$(‘#tt‘).datagrid(‘deleteRow‘,index); //通过行号移除该行
}
}
//获取页面中选择行的id和数量
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;
//日期格式的文本输入框
<input id="dd" class="easyui-datebox" ></input>
[转] easyui 获取数据表格中选中行的数据 Get selected row data from...
标签:
原文地址:http://www.cnblogs.com/dirgo/p/5106142.html