EasyUI Forum

General Category => Bug Report => Topic started by: alex.capurro on May 28, 2012, 07:12:52 AM



Title: datagrid.getSelections is not returning selected rows
Post by: alex.capurro on May 28, 2012, 07:12:52 AM
Hi,

I have a table that i am creating with code, ie:

Code:
$('#users').datagrid({
title : 'Users',
iconCls : 'icon-user',
width : '100%',
height : 'auto',
nowrap : true,
striped : true,
collapsible : false,
url : "/getUsers",
sortName : 'userId',
loadMsg: 'Loading data form server..',
sortOrder : 'desc',
remoteSort : true,
idField : 'userId',
doSize:true,
fit:true,
columns : [ [ {
title : 'User ID',
field : 'userId',
width : 60,
sortable : true
}, {
field : 'username',
title : 'Username',
width : 90,
rowspan:2,
sortable : true,
sorter : function(a, b) {
return (a > b ? 1 : -1);
}
} , {
field : 'name',
title : 'Name',
width : 350,
rowspan:2,
sortable : true,
sorter : function(a, b) {
return (a > b ? 1 : -1);
}
} ] ],
pagination : true,
rownumbers : true
});

I then have a button that when you click on it calles this function:

Code:
function getSelections(){
var ids = [];
var rows = $('#users').datagrid('getSelections');
for(var i=0;i<rows.length;i++){
ids.push(rows[i].id);
alert(ids[i]);
}
}

However no matter how many rows i select, the rows variable only shows me 1 selection (the last one i choose).

Here is the html of my table:

Code:
<table id="users" maximizable="false" toolbar="#userSearchtb"></table>


Title: Re: datagrid.getSelections is not returning selected rows
Post by: alex.capurro on May 30, 2012, 03:43:44 AM
Actually i solved the problem. It was because the idField of the table i was using was incorrect.

it appears that the getSelections uses the idField property so you need to make sure that the idField is actually the same as the one passed in the json data.