PDA

View Full Version : Getting Row Index of GridPanel



auction123
21 Oct 2009, 7:19 AM
I have a grid panel that i need to manually select the index of.
When scrolling, the id's of the items change so that does not work.
I have tried:

GridPanelExports.getSelectionModel().getSelected()

But that only returns an object with an id, but the id is NOT the index.

How would i go about selecting a row in a grid panel that has no unique fields?

lyle
22 Oct 2009, 7:21 AM
Can you try using the rowselect, beforerowselect or selectionChange events on the grid? They all return a row index. One way is to stuff that value into a hidden form field each time it changes, so it is always available.

In the rowselect listener:

function(select,rowNum,rec) {
Ext.getCmp('theHiddenField').setValue(rowNum);
}

Then when you want the currently selected row call:
curRow = Ext.getCmp('theHiddenField').getValue;

Hope that helps.

auction123
26 Oct 2009, 7:17 AM
I don't think thats quite it.

If it can be stored in a hidden field, how does the hidden field get the value?

I just need a way to get index... the number of the selected row (not the id of the item).

GridPanel.getSelectionModel().getSelected()
does not work.

It just seems like theres no way of doing this. But it is possible for some reason to do the opposite:
GridPanel.getSelectionModel().selectRow( INDEX )

Like i said, just trying to get the index (the row number, first, second) somehow.

Animal
26 Oct 2009, 7:35 AM
What does getSelected return? (There's no getSelectedRow, you just invented that)

lyle
26 Oct 2009, 7:45 AM
Create an event listener on your grid -- for the event "rowselect"
Put the following function in that event listener.

function(select,rowNum,rec) {
Ext.getCmp('theHiddenField').setValue(rowNum);
}


The event for the grid -- rowselect returns three items, the the selectionmode, the row number and the record. In my example above the row number = rowNum.

I set it to a hidden field = theHiddenField. That's how the theHiddenField gets the row number value.

lyle
28 Oct 2009, 11:25 AM
Here's another thought, something I ran across today. Doesn't work for me, but maybe it will for you. This is version 2.0 so please lookup or adjust accordingly if you are using version 3.

From EXTJS 2.2.1 API Documentation
// This is a typical column config with the first column providing row numbers
var colModel = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{header: "Name", width: 80, sortable: true},
{header: "Code", width: 50, sortable: true},
{header: "Description", width: 200, sortable: true}
]);

srivaspu
11 Nov 2009, 4:05 AM
Ext.grid.RowSelectionModel.override ({
getSelectedIndex : function(){
return this.grid.store.indexOf( this.selections.itemAt(0) );
}
});then you can use the function getSelectedIndex(), e.g.,
GridPanelExports.getSelectionModel().getSelectedIndex()

riya_phoenix
18 Nov 2009, 1:10 PM
Thanks srivaspu (http://www.extjs.com/forum/member.php?u=40403)

tobiu
31 Dec 2009, 8:25 AM
Ext.grid.RowSelectionModel.override ({
getSelectedIndex : function(){
return this.grid.store.indexOf( this.selections.itemAt(0) );
}
});


+1 feature request

Stju
7 Mar 2010, 8:10 PM
+1 feature request

Stju

ZeusTheTrueGod
8 Mar 2010, 12:12 AM
Why feature request? I vote against including something new into grid

Make a plugin and publish it. Ext.ux.RowActions , DragAndDrop,RowEditor and many other usefull grid plugins lives without feature request. Can you imaginate the size of monolith Ext.grid.GridPanel where each feature request is implemented?