PDA

View Full Version : Grid addSorted index



ValterBorges
20 Jul 2009, 10:31 AM
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

ValterBorges
20 Jul 2009, 11:10 AM
Here is what i've done as a workaround. If anyone has a better solution let me know.

Thanks,


//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);
}

pmatsumura
20 Jul 2009, 11:21 AM
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

ValterBorges
20 Jul 2009, 11:27 AM
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.

pmatsumura
20 Jul 2009, 11:29 AM
I meant using the "code" button in the post editor. Please use that to display code in a forum post.

Thanks,
Patrick

ValterBorges
20 Jul 2009, 11:33 AM
All set.

mjlecomte
20 Jul 2009, 12:45 PM
How about adding a listener for the add event?

ValterBorges
20 Jul 2009, 3:53 PM
Thanks that worked great.





storeCompanies.on('add',storeCompaniesOnAdd);


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