PDA

View Full Version : Grid sort: How to act on column sort before sort operation is performed



yyogev
21 Oct 2012, 11:23 PM
Hi,

I have a query view where the results are displayed in a grid. The users have the options to save queries with the sort order. When the user loads a saved query, I set the store.proxy.extraParams to indicate the order to be used.
However, when the user chooses to sort the data differently by clicking on the column headers, or by choosing sort order from the column header menu, I need to remove the saved order from the the extraParams.

I tried to do this using the sortchange event, but I found that the sortchange event is fired only after the call to doSort(). I also tried to override onSortAscClick and onSortDescClick, but it did not work.

Any ideas how to do this ?

Barzoy
22 Oct 2012, 3:32 AM
Try to use grid store sorters (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-property-sorters) instead of modifying of proxy extra params. Grid complitely clears store sorters each time user initiates any sorting operation. Personally, I prefer acting same way with grid filters.
As for me, this practice is preferable because application logic (applying user dataview preset in your case) shouldn't know anything about databinding backend, proxys, datatransfer formats, package envelopes etc - all this crap has no matter for it.



function applyPreset(preset, store) {
store.sorters.clear();
store.sorters.addAll(preset.getSorters());
store.filters.clear();
store.filters.addAll(preset.getFilters());
store.load(); // for remote stores only
}

yyogev
22 Oct 2012, 4:10 AM
Hello Barzoy,

Thanks for your answer. I did consider this, but my preset is not always using columns that are in the store. It gives a sort order which refers to fields that are not necessarily in the grid.

I have to explain here that in my query view the user can select what columns to show, and there are dozens of possible columns, many of which require JOIN on external DB tables, so I cannot possibly have all the columns in the grid columns list all the time. I have a dialog window allowing the user to do the selection of columns.

The question is this: if I want to convey the preset order through the sorter, can I put just any value in the sorters, as this grid uses a remote sort ?

Thanks,

yyogev
22 Oct 2012, 4:22 AM
Another point to consider: when the user changes the sort order I keep the changed state.
If I load a saved query, I want to use the preset order without modifying the state.

Barzoy
22 Oct 2012, 4:38 AM
Does your serverside SQL expression depends on list of visible columns or set of joined tables always the same? If the set of joinedtables varies then you have to filter list of sorters with Ext.Array.filter (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Array-method-filter) before you pass them into the store.

yyogev
22 Oct 2012, 5:26 AM
The preset sorters can contain contain columns that are not not in the store currently. The back-end script knows the column definitions and can handle this properly. However, if I pass it via Array.filter than it will probably never get to the server, which defeats the purpose of this.

I guess I'll just have to experiment with this and see if I can use the sorters to keep names of external properties (i.e. names which do not appear in the store's fields list).

rgralhoz
29 Oct 2013, 1:28 PM
Hi, @slemmon
Regarding http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-sort , the `beforesort` event is not documented and it doesn't stop sorting if the event handler returns false (as with `beforeload`).

Should I file a bug?