Jump to content

How to change uniDbGrid default sort order on some columns?


alfr

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...