user765368
user765368

Reputation: 20346

get unselected datagrid row jquery easyui

I'm using the jQuery EasyUI datagrid to present some data to my users. I know how to get the data of the row that is selected in the datagrid by using:

var selectedRow = $('#my_datagrid_id').datagrid('getSelected');

But does anybody know how I can get a particular row in my datagrid by its id or something (without having the row selected)?

I can't seem to find anywhere how to do this

Thanks in advance

Upvotes: 1

Views: 8638

Answers (4)

SinaSarparast
SinaSarparast

Reputation: 101

As you know to find all rows you should try this:

var allRows = $('#my_datagrid_id').datagrid('getRows');

To get selected rows:

var selectedRows = $('#my_datagrid_id').datagrid('getSelections');

Suppose you know Index of your particular row which we assume this Index as 5. To find if this special row is get selected or not:

var specialRow= $.grep(selectedRows , function (e) {
   return e == allRows[5];
});
if(specialRow.length>0)
alert('Voila! The Row is selected');
else
alert('Nope! The Row is not selected');

By $.grep you can search in an array (in our context, in selected rows) and if your particular row was inside the array(selected rows) you will be returned with a filled specialRow array.

Upvotes: 0

Saigitha Vijay
Saigitha Vijay

Reputation: 466

Can you try,

if you want to get the row with Id "01",

var row=$('#my_datagrid_id').datagrid('getRows')[$('#my_datagrid_id').datagrid('getRowIndex','01')];

Upvotes: 1

Danang Ponorogo
Danang Ponorogo

Reputation: 89

Try this one, then I think you will know what to do next :)

var myData = $('#my_datagrid_id').datagrid('getData');
alert('myData : ' + JSON.stringify(myData));

Upvotes: 2

bipen
bipen

Reputation: 36531

u can use... getRows to get all the rows and loop thourgh the rows..

 var rows=$('#my_datagrid_id').datagrid('getRows');
 if(rows.length == 0)
 {
     alert('no row present');
 }else{
    for(i=0;i<rows.length;i++)
    {
       //do your stuff here.. if your want particular row then u can use if condition 
    }
 }

OR

if u know the index of the row u wanted, then u can use getRowIndex method

go through the documentaion here

Upvotes: 0

Related Questions