Change additional store options before the grid sort event

Demand

Every time the grid data is sorted - before the event is completed, I want to change the extraParams store with the values โ€‹โ€‹of the new sort properties. For example, if I sort the column name in the DESC direction - before the event is completed , I want to overwrite extraParams in the repository using the dataIndex of the Name column and the DESC property. Direction

My store also has a remoteSort property set to true .

I am using ExtJS 4.2.

Problem

I tried the sortchange event sortchange on the grid, but it executes after calling the data API and loading the records. What I would like to have is something like beforesortchange.

All this with remoteSort : true .

The next problem: if I call this.getStore().load(); from sortchange , then my api data is called twice, which makes no sense.

Code

Mesh receiver:

 sortchange: function(ct, column, direction, eOpts) { this.getStore().getProxy().extraParams = { 'sort' : column.dataIndex, 'dir' : direction } // load() will call the data api again once the data loading is over //this.getStore().load(); } 

I also tried mesh listeners, but either I do not get new grid sorting options or they are not called at all: beforeload , beforesync , beforeprefetch , load .

References

stack overflow

+4
source share
1 answer

Use the beforeload event to modify the extraParam object before sending it:

 listeners: { beforeload: function(store, operation, eOpts){ if(store.sorters && store.sorters.getCount()) { var sorter = store.sorters.getAt(0); store.getProxy().extraParams = { 'sort' : sorter.property, 'dir' : sorter.direction }; } } } 
+4
source

Source: https://habr.com/ru/post/1491882/


All Articles