alfr Posted October 14, 2020 Share Posted October 14, 2020 In an uniDbGrid I need to change the default sort order on some of the columns when a user first clicks on the column header. The default sort order is Ascending, but on column 3, 4, 5, 6, 7, 8 I need to instead have the sort order Descending when user do first click on column (and then if click again Ascending). How can the following Sencha js-code be applied to reconfigure the uniDbGrid toggleSortState function on columns[2..7]? columns: [{ dataIndex: 'id', text: 'ID', width: 50, toggleSortState: function() { if (this.isSortable()) { var me = this, grid = me.up('tablepanel'), store = grid.store, sortParam = me.getSortParam(), direction = undefined; if(!store.getSorters().get(sortParam)) { direction = 'DESC'; } this.sort(direction); } }, } Sencha fiddle sample: https://fiddle.sencha.com/#fiddle/17u2&view/editor UniGui Professional 1.90.0.1537 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted October 14, 2020 Share Posted October 14, 2020 5 hours ago, alfr said: In an uniDbGrid I need to change the default sort order Hello, This post may help you, can you check it? Quote Link to comment Share on other sites More sharing options...
alfr Posted October 14, 2020 Author Share Posted October 14, 2020 Hi, Thanks for getting back. I've already search much in the forum and the web to try to get a solution, but my skills in JavaScript is not that good. The post that you are referring to sets the sort on an column to Ascending, but what I'm after is to change/set the toggleSortState initial value on some of the columns as many of the numeric columns should sort Ascending when a user later clicks on one of them. I thought it would be quite easy(?) to do this change for a person more into JavaScript, but perhaps it's not that easy? Regards Alf Quote Link to comment Share on other sites More sharing options...
Sherzod Posted October 15, 2020 Share Posted October 15, 2020 7 hours ago, alfr said: Thanks for getting back. I've already search much in the forum and the web to try to get a solution, but my skills in JavaScript is not that good. The post that you are referring to sets the sort on an column to Ascending, but what I'm after is to change/set the toggleSortState initial value on some of the columns as many of the numeric columns should sort Ascending when a user later clicks on one of them. I thought it would be quite easy(?) to do this change for a person more into JavaScript, but perhaps it's not that easy? Hi, Maybe I don't really understand your case. Can you please clarify once again by specifying in screenshots, attaching a test case? Quote Link to comment Share on other sites More sharing options...
alfr Posted October 16, 2020 Author Share Posted October 16, 2020 As I wrote: On 10/14/2020 at 11:50 AM, alfr said: I need to change the default sort order on some of the columns when a user first clicks on the column header. The default sort order is Ascending, but on column 3, 4, 5, 6, 7, 8 I need to instead have the sort order Descending when user do first click on column (and then if click again Ascending). I've tried a lot of different things, but when getting down to these details around the ExtEvents in uniGui, it's quite time consuming as it is sometimes hard to know what is possible. In the end I've succeded with my needs by doing two things. 1. First I managed to change the default sort order on the complete grid by doing the following. function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) { oldStore.getSorters().$sortable.setDefaultSortDirection('DESC'); } I had to use "oldStore", as "store" seem not to be populated? (Extjs7?) 2. As the first column should continue to have default sort set to ASC, I instead did a bit ugly hardcoding to always sort it ASC. (There is no need to sort this alpha string column descending). function headerclick(ct, column, e, t, eOpts) { if (column.dataIndex == 0) { column.sort('ASC'); } } So not exactly what our client wanted to have, but almost. But a problem is that these kind of things takes quite much time to nail down... Quote Link to comment Share on other sites More sharing options...
Sherzod Posted October 16, 2020 Share Posted October 16, 2020 24 minutes ago, alfr said: I need to change the default sort order on some of the columns when a user first clicks on the column header. The second click will be descending... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.