EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: kudoof on November 08, 2013, 01:42:57 AM



Title: index of a selected row with duplicate content in datagrid
Post by: kudoof on November 08, 2013, 01:42:57 AM
This was asked by someone but the answer like the following does not serve my purpose...
Code:
var dg=$('#dg');
var selected = dg.datagrid('getRowIndex',dg.datagrid('getSelected')));

So I have a table that has two identical records in it.  When the second identical record is selected ,  I want to get its index, not the first one.  The code above will give me the first index instead.   I know I could have used a unique id field but that adds to complexity and I am almost sure there is a simple method to just get index of THE selected row.   Just couldn't find it in the documentation page... Help




Title: Re: index of a selected row with duplicate content in datagrid
Post by: kudoof on November 11, 2013, 03:48:38 PM
Hello?


Title: Re: index of a selected row with duplicate content in datagrid
Post by: stworthy on November 11, 2013, 05:18:20 PM
Calling 'getRowIndex' method will return the specified row index. What you need to do is to pass the row object to this method.
Code:
var row = ...;  // the row object
var idx = $('#dg').datagrid('getRowIndex', row);
alert(idx);


Title: Re: index of a selected row with duplicate content in datagrid
Post by: kudoof on November 12, 2013, 08:59:32 AM
Thanks, but how to get the row object of the selected row? Couldn't find it in the doc.  'getSelected' only returns the rowData.   


Calling 'getRowIndex' method will return the specified row index. What you need to do is to pass the row object to this method.
Code:
var row = ...;  // the row object
var idx = $('#dg').datagrid('getRowIndex', row);
alert(idx);

Btw,  the documentation said the following, so I guess it needs to be updated:
getRowIndex   row   Return the specified row index, the row parameter can be a row record or an id field value.


Title: Re: index of a selected row with duplicate content in datagrid
Post by: yupengfei on November 15, 2013, 01:44:58 AM
This was asked by someone but the answer like the following does not serve my purpose...
Code:
var dg=$('#dg');
var selected = dg.datagrid('getRowIndex',dg.datagrid('getSelected')));

var selections= dg.datagrid('getRowIndex',dg.datagrid('getSelections')));
var ids = [];
$.each(Selections, function(i, e){
    var index = dg.datagrid('getRowIndex', e);
    if(ids.contains(e.id)){
       console.info('exists index -->>' + index)
    }else{
      ids.push(e.id);
   }
});



Title: Re: index of a selected row with duplicate content in datagrid
Post by: kudoof on November 18, 2013, 10:23:27 AM

This doesn't address the identical entries problem, as the 'getSelections' would return the rowData instead of the object.

Quote
Code:
var selections= dg.datagrid('getRowIndex',dg.datagrid('getSelections')));
var ids = [];
$.each(Selections, function(i, e){
    var index = dg.datagrid('getRowIndex', e);
    if(ids.contains(e.id)){
       console.info('exists index -->>' + index)
    }else{
      ids.push(e.id);
   }
});



Title: Re: index of a selected row with duplicate content in datagrid
Post by: kudoof on November 22, 2013, 12:17:19 PM
How to get the row object?


Title: Re: index of a selected row with duplicate content in datagrid
Post by: stworthy on November 23, 2013, 02:21:11 AM
The 'getSelections' method returns all the selected rows. You must iterate through this returned array to get the corresponding row index.
Code:
var selections = dg.datagrid('getSelections');
for(var i=0; i<selections.length; i++){
var index = dg.datagrid('getRowIndex', selections[i]);
console.log(index);
}


Title: Re: index of a selected row with duplicate content in datagrid
Post by: ftmh on February 01, 2014, 04:21:05 AM
hi i don't know how to add the right-click select in my data grid row! tanks