PDA

View Full Version : Sorting a BufferedGrid



strickjb
19 Jan 2012, 6:26 AM
Sorting in a BufferedGrid sorts the store's loaded/rendered data.

What I'd like to have happen is for it to sort the prefetched data and then recalculate/reload the rows within the scroller's view.

Would it be an easy task to make the grid's column sort functions sort the store's prefetch data?

strickjb
19 Jan 2012, 7:20 AM
I created an Override method using the existing Ext.data.Store sort method.

The below solution is based on:

http://www.sencha.com/forum/showthread.php?174760-Reloading-a-BufferedGrid&p=716157


Ext.define('My.store.BufferedStore', {
extend: 'Ext.data.Store',

buffered: true,
pageSize: 100,
purgePageCount: 0,

//@Override
sort: function(sorter) {
var me = this,
prefetchData = me.prefetchData,
sorters,
start,
end,
range;

if(sorter) {
sorter.root = 'data';
}

sorters = sorter ? [sorter] : me.getSorters(); //Modified

me.sorters.clear();
prefetchData.sorters.clear();

me.sorters.addAll(sorters); //this calls the original store method of sort???

start = me.guaranteedStart;
end = me.guaranteedEnd;

if (sorters.length) {
prefetchData.sort(sorters);
range = prefetchData.getRange();
prefetchData.clear();
me.removeAll(); //Added
delete me.guaranteedStart;
delete me.guaranteedEnd;
delete me.totalCount; //Added
me.cacheRecords(range);
me.guaranteeRange(start, end);
}

me.callParent(arguments);
}

});

Also I added a listener to the grid for 'sortchange' :



onSortChange: function (cont, column, dir) {
if(!!dir) {
this.getGrid().setScrollTop(0);
}
}