Page 1 of 2

[ANSWERED] click Sort icon of column header programmatically

Posted: Sat Mar 07, 2020 3:18 pm
by eguardiola
Hi,

How the sort icon of a column header can be clicked programmatically?

Thanks!

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 10:16 am
by mats

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 10:37 am
by eguardiola
Thanks.

- I'm defining a custom sorter for the 'startDate' column.
- When i click on the sort icon the custom sorter is called and everything works well.
- When i call to store.sort('startDate') my custom sorter is not called and the sorting is wrong..

- If a call store.sort(myfuncion) with my custom sorting function the sorting works but the sort icon on the column doesn't remain pressed so the sorting is lost when the filtering is changed. That's why i'm trying to click the sorting icon button programmatically because when i click it by hand all works as i need.

¿Any tip?

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 12:44 pm
by mats
- When i call to store.sort('startDate') my custom sorter is not called and the sorting is wrong..
Why would you expect
store.sort('startDate')
to call your sorter? store.sort('foo') sorts by the data field 'foo'.

Can you please provide a simple test case and we'll try to help

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 1:01 pm
by eguardiola
I mean that if in the column config you provide a custom sorting function in the sortable property this function is called when you click on the sort icon of the header but is not called when you call it by code: store.sort('foo')

https://bryntum.com/docs/scheduler/#Grid/column/Column#config-sortable

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 1:53 pm
by mats
store.sort('foo')
This just sorts the store by a field called foo in your data model, it has nothing to do with the Column.

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 2:31 pm
by eguardiola
Thanks. I now understand that this sort call has nothing to do with the Column. So.. can i click the sort icon of the column programmatically? I need the icon visual pressed status and the sorting to remain between filtering changes. From a user point of view i need not having to press the sort icon to get the sorting the first time the grid is presented to the user. I need to sort one concrete column by default as when i click the sort icon but not having to.

Re: click Sort icon of columna header programmaticaly

Posted: Mon Mar 09, 2020 5:08 pm
by mats
Try passing in column (which has the field + sortable properties):
grid.store.sort(grid.columns.last)

Re: click Sort icon of columna header programmaticaly

Posted: Tue Mar 10, 2020 9:23 am
by eguardiola
Thanks but that has the same effect as grid.store.sort('startDate'). It is sorting but not by using the sorting function passed in the sortable property when configuring the column. Only clicking by hand on the sorter icon of the column is using that sorting function.

Re: click Sort icon of columna header programmaticaly

Posted: Tue Mar 10, 2020 10:58 am
by eguardiola
Could be possible to take the sorting widget on the header column and simulate a mouse click event on it?