EasyUI Forum
April 30, 2024, 10:27:29 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: index of a selected row with duplicate content in datagrid  (Read 18782 times)
kudoof
Newbie
*
Posts: 21


View Profile
« 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


Logged
kudoof
Newbie
*
Posts: 21


View Profile
« Reply #1 on: November 11, 2013, 03:48:38 PM »

Hello?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 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);
Logged
kudoof
Newbie
*
Posts: 21


View Profile
« Reply #3 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.
« Last Edit: November 12, 2013, 10:08:33 AM by kudoof » Logged
yupengfei
Newbie
*
Posts: 10


View Profile
« Reply #4 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);
   }
});

« Last Edit: November 15, 2013, 01:54:08 AM by yupengfei » Logged
kudoof
Newbie
*
Posts: 21


View Profile
« Reply #5 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);
   }
});

Logged
kudoof
Newbie
*
Posts: 21


View Profile
« Reply #6 on: November 22, 2013, 12:17:19 PM »

How to get the row object?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #7 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);
}
Logged
ftmh
Newbie
*
Posts: 19


View Profile
« Reply #8 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!