View Full Version : Show items in grid in reverse order

12 Jul 2013, 12:57 AM

I would like to show items in grid in reverse order. I mean when I add an item to linked store, last added item will be on top of grid (first line) and all previous items will be shifted down.
I searched API for both Ext.data.Store and Ext.grid.Panel classes however could not find any corresponding config item or property.
Is there a short way to do this? (Or should I implement it myself by listening datachanged event and manipulating the store to reverse order of items?)

Thanks for any help

12 Jul 2013, 1:11 AM
how about sorting the store according to id. if you have monotonically increasing ID, then sorting the store by ID will automatically order the records.

12 Jul 2013, 4:40 AM
Do you suggest to add field "id" to my store's model?

My model is

Ext.define('MyApp.model.ConsoleItem', {
extend: 'Ext.data.Model',
fields: [
{name:'consoleLine', type: 'string'},
{name: 'isError', type: 'boolean'}

I do not want to add new field to store, because I need to increase/descrease it everytime I have data addition / removal to my store.

Is there something like sorting by index DESC?

12 Jul 2013, 4:55 AM
without a unique field in your records (index or id), how do you know which record is newest and which one is older?

if this store is only for your frontend and doesn't communicate with your backend, then you can use store's insert method to insert new records at a particular position e.g. use index 0 to add the record to top. however, if the user clicks the grid's header to sort, the ordering will be lost. you should also then disable the sorting for grid columns.

12 Jul 2013, 6:31 AM
Actually insert(index, ..) solves my problem. Thanks for the answer.
The solution was too easy to be recognized by me :">

12 Jul 2013, 6:35 AM
yeah that happens. we tend to overlook whats directly in front of us.