EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: tomhj on July 16, 2012, 01:38:26 PM



Title: Getting row data for a particular index
Post by: tomhj on July 16, 2012, 01:38:26 PM
Perhaps I'm overlooking it, but I don't see a way to get the data for a row in a datagrid based on it's index.  getSelected()  and getSelections() returns the row data for the selected row (or rows) and I see the getData() function - but I dont see a getData(index) method.

Is there a way to get that?


Title: Re: Getting row data for a particular index
Post by: stworthy on July 16, 2012, 03:23:01 PM
To get a particular index row, please call getRows method.
var rows = $('#dg').datagrid('getRows');
var row = rows[index];


Title: Re: Getting row data for a particular index
Post by: tomhj on July 16, 2012, 05:18:13 PM
Does that work even if the data is paginated?   Not sure if the first row on each page restarts at index=0.


Title: Re: Getting row data for a particular index
Post by: stworthy on July 16, 2012, 08:47:36 PM
The 'getRows' method return the current page rows. The first row index of each page is 0, the second row index is 1, etc.


Title: Re: Getting row data for a particular index
Post by: tomhj on July 17, 2012, 09:18:26 AM
Great - added the following to my code; works well.

Perhaps this would make a nice addition to the library?

$.extend($.fn.datagrid.methods, {
       getDataForIndex: function(target, index){
           var rows = $(target).datagrid('getRows');
             return rows[index];
             }
});

Thanks


Title: Re: Getting row data for a particular index
Post by: Radikal on August 26, 2013, 09:36:07 AM
Code:
var row = $('#dg').datagrid("getRows")[index];