1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    15
    Vote Rating
    0
    djdevz is on a distinguished road

      0  

    Default 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.

    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 {}
                
            });
    Any help is greatly appreciated, and this is my first post so apologies if I've missed anything out.

  2. #2
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    Try something like this:

    Code:
    var targetRowIndex = grid.store.find('id', id);

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    15
    Vote Rating
    0
    djdevz is on a distinguished road

      0  

    Default


    legend! it works!
    except i used 'store.find' rather than 'grid.store.find'
    (shouldn't make a difference though, right?)
    Code:
                    var rowIndex = store.find('id', id);            
                    grid.getSelectionModel().selectRow(rowIndex);
                    grid.getView().focusRow(rowIndex);
    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);
                    alert(rowIndex);
    Otherwise there is no focus in FF...Any thoughts?

    Appreciate the help!

  4. #4
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    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)

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    15
    Vote Rating
    0
    djdevz is on a distinguished road

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    Apr 2011
    Posts
    15
    Vote Rating
    0
    djdevz is on a distinguished road

      0  

    Default


    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

  1. List Store index is not sorted based on Grouping.
    By tomalex0 in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 6 Sep 2011, 3:12 AM
  2. Getting Row Index of GridPanel
    By auction123 in forum Ext 3.x: Help & Discussion
    Replies: 10
    Last Post: 8 Mar 2010, 12:12 AM
  3. Replies: 3
    Last Post: 27 Aug 2009, 2:06 AM
  4. ROW INDEX OF GridPanel
    By Imran Bashir in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 27 Aug 2008, 10:25 PM
  5. Finding index in jsonData by field value
    By steffenk in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 26 Aug 2007, 1:45 PM

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."