Results 1 to 8 of 8

Thread: Grid addSorted index

  1. #1
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      0  

    Default Grid addSorted index

    Is there a way to get the last inserted row without having to use find when using the addSorted method? The problem i'm having with find is that rows are not necessarily unique unless i added a additional column/row counter. It would be nice if addSorted returned the index where the row was inserted.

    Thanks,
    Valter

  2. #2
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      0  

    Default workaround

    Here is what i've done as a workaround. If anyone has a better solution let me know.

    Thanks,
    Code:
    //prior to the code below a field is defined as
    //{name: 'key', type:'int'}
    //a column is defined as 
    //{id:'key',dataIndex:'key',hidden:true}
    
    
    
    var Company  = storeCompanies.recordType;
    
    var c = new Company({
                                  key: storeCompanies.getCount() + storeCompanies.getTotalCount();
                                  company: 'CompanyX',
                                  price: 99.99
                                  });
    
    var rowIndex = 0;
    
    storeCompanies.addSorted(c);
    rowIndex = storeCompanies.find('key',c.data.key,1,false,true);
    
    //if you want to focus to the first row set rowIndex = 0
    //if you want to focus to the last row set rowIndex = store.getCount()  /*Scroll Issue fixed in SVN 3.0+*/
    
    if(rowIndex !== -1)
    {
       gridCompanies.getSelectionModel().selectRow(rowIndex);
       gridCompanies.getView().focusRow(rowIndex);
    }

  3. #3
    Ext JS Premium Member
    Join Date
    Jun 2009
    Location
    Switzerland
    Posts
    83
    Vote Rating
    0
      0  

    Default

    Hi ValterBorges,

    could you maybe edit your post, so other can read the code easier? It's rather difficult, when it's not formatted.

    Thanks,
    Patrick

  4. #4
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      0  

    Default Not sure what you mean

    Not sure what you mean by formated, can you please clarify.


    If you're refering to it not being in JSON format and more OO format like that's because I find it easier to maintain and read this way and more maintainable.

  5. #5
    Ext JS Premium Member
    Join Date
    Jun 2009
    Location
    Switzerland
    Posts
    83
    Vote Rating
    0
      0  

    Default

    I meant using the "code" button in the post editor. Please use that to display code in a forum post.

    Thanks,
    Patrick

  6. #6
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      0  

    Default Code format

    All set.

  7. #7
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    8
      0  

    Default

    How about adding a listener for the add event?

  8. #8
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      0  

    Default Works great.

    Thanks that worked great.

    Code:
    storeCompanies.on('add',storeCompaniesOnAdd);  
    
    
    function storeCompaniesOnAdd(Store,records,index)
    {
      gridCompanies.getSelectionModel().selectRow(index);
      gridCompanies.getView().focusRow(index);   //Fix in SVN for EXT 3.0+
    };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •