-
4 May 2011 3:05 AM #1
GridPanel - Finding a Row Index Based on a Value
GridPanel - Finding a Row Index Based on a Value
Hi, my aim is to select a row in the grid (and focus on the row), based on the 'egId' value in a (plain HTML) textbox.
for instance if the 'egId' value = 10
then I would like the record in the grid to be selected where the column called 'id' contains a value of 10 (not the record id).
The first 'if' in the code below is for when the 'egId' field is null. But when it is not null, this is when I'd like the grid to select the record based on the 'egId' field.
I tried using findRowIndex(), but whatever I enter returns 'false',
and the focusRow() and selectRow() methods has '8' as the parameter as I was just testing to see how they work.
Any help is greatly appreciated, and this is my first post so apologies if I've missed anything out.Code:var id = Ext.getDom('egId').value; var fieldValue = Ext.getDom('egFieldValue').value; store.on('load', function() { if (!id && fieldValue) { grid.getSelectionModel().selectFirstRow(); } else if(id && fieldValue) { var rowIndex = sapLinkGrid.getView().findRowIndex(id); alert(rowIndex); grid.getSelectionModel().selectRow(8); grid.getView().focusRow(8); } else {} });
-
4 May 2011 3:52 AM #2
Try something like this:
Code:var targetRowIndex = grid.store.find('id', id);
-
4 May 2011 4:11 AM #3
legend! it works!
except i used 'store.find' rather than 'grid.store.find'
(shouldn't make a difference though, right?)
Just a little off topic, but the 'focusRow()' method works fine in IE, but will only work in FF if I place an alert after 'rowIndex':Code:var rowIndex = store.find('id', id); grid.getSelectionModel().selectRow(rowIndex); grid.getView().focusRow(rowIndex);
Otherwise there is no focus in FF...Any thoughts?Code:var rowIndex = store.find('id', id); alert(rowIndex);
Appreciate the help!
-
4 May 2011 4:50 AM #4
You're correct, 'store.find()' is perfectly okay, so long as variable 'store' is in scope.
For focusing a row in the grid, try this instead:
Code:grid.selModel.selectRow(rowIndex)
-
4 May 2011 5:40 AM #5
Thanks 'friend' you've really helped me out here...
It seems there's a logical issue that I've come across though.
the if else if statement I posted is for 'add' and 'update',
- if you add a record, there won't be an 'id' in my field (it gets generated by the back end, and the grid picks it up when it's reloaded)
- if you update a record, there will be an 'id' in my field (because upon selection of a record in the grid, I transfer the fields from the grid to the html fields)
So with the first 'if' statment (adding), I select the first row, because the grid is sorted by 'id' (desc), so that the newest records are at the top, therefore selected the record that has been added.
However if the user sorts the grid using another column, the added record doesn't go to the top meaning when I select the first row, I'm selecting the wrong record!
My work around idea is to search for the record with the id greater than the current highest id, (as the generator will always produce a higher number), as to find the newly created record.
Is this possible/any ideas on how to do this?
Sorry for the rambling, but I wanted to make sure I portrayed my logic and problem properly.
Thanks again.
-
4 May 2011 6:12 AM #6
no worries I just sorted it by 'id' as default,
so the user has to sort the columns manually again after adding a record.
Similar Threads
-
List Store index is not sorted based on Grouping.
By tomalex0 in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 6 Sep 2011, 3:12 AM -
Getting Row Index of GridPanel
By auction123 in forum Ext 3.x: Help & DiscussionReplies: 10Last Post: 8 Mar 2010, 12:12 AM -
[2.2.1] Finding the currently editable cell (the current cell) of the GridPanel
By r_honey in forum Ext 2.x: Help & DiscussionReplies: 3Last Post: 27 Aug 2009, 2:06 AM -
ROW INDEX OF GridPanel
By Imran Bashir in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 27 Aug 2008, 10:25 PM -
Finding index in jsonData by field value
By steffenk in forum Ext 1.x: Help & DiscussionReplies: 3Last Post: 26 Aug 2007, 1:45 PM


Reply With Quote