PDA

View Full Version : changing the initial sort direction of a table column to DESC



pillindra
30 Jun 2008, 10:33 AM
When I click on one of the TableColumn that has sorting enabled (using Table/TableColumn API) but not sorted initially, the first sort is always ASC. Is there any option to change the first sort direction on clicking a column header to DESC when I click first time on the TableColumn header.

Thanks,
Padma

gslender
30 Jun 2008, 1:59 PM
Did this not work? http://extjs.com/forum/showthread.php?t=39842

pillindra
30 Jun 2008, 2:39 PM
glsender,

That worked for showing the sorting icons on the column header after the table is rendered initially which is very helpful from the usability point of view to know the sort direction. But, in case of using Table, clicking on any other column that is not part of Deferred command, first sorts the table by ASC.

For Example, if I have 5 columns in a table. I sort the table by 3 rd column in ASC and show the sorting Icon after the table is rendered as shown below with the solution that you have provided in the previous thread

DeferredCommand.addCommand(new Command() {
public void execute() {
tbl.getTableHeader().sort(2, SortDir.ASC);
}
});

This part works fine.

Then user clicks on column 1 of the table. Then, the column values are sorted by ASC first. Is there any way, to make this sorted by DESC first. To resolve this, I tried adding the following to the DeferredCommand which provided a work around for me. (sorting column 1 by ASC when table is rendered, so user click once again makes it DESC)

DeferredCommand.addCommand(new Command() {
public void execute() {
tbl.getTableHeader().sort(0, SortDir.ASC);
tbl.getTableHeader().sort(2, SortDir.ASC);
}
});

But, when I switch clicking between sorting of different columns, every column remembers the last sort I have made. Basically this Sorting toggles rather than resetting after clicking another column. Is there any easiest way of resetting sorting of a column after clicking another column to the one mentioned in DeferredCommand.

Thanks,
Padma

gslender
30 Jun 2008, 6:42 PM
what about using Table.sort to set the default and Table.getHeader.setSort to change the default heading?

gslender
30 Jun 2008, 6:49 PM
I may have led you down the wrong path - I think this might be the solution....

1) use Table.sort() in a deferred command to ensure it is rendered and it will do the getTableHeader().sort(index, sortDir) for you.

2) extend TableColumn class and override the default protected SortDir sortDir = SortDir.NONE to be whatever you want the default to be for every column.

That should work (I think ;) )

pillindra
1 Jul 2008, 8:36 AM
gslender,

The solution in item (1) does resolve the issue partially and thanks for your input. But I am still looking in to resolution for 'Sorting toggles rather than resets after clicking another column'.

Thanks,
Padma

gslender
1 Jul 2008, 1:02 PM
pillindra,

Seems like Table kinda has bug (more of a usability issue than code) and I doubt it would be fixed considering Grid is where all the effort for the new table-like widget is going to be. I'm guessing it won't be long before a working gird with all the correct behaviour will be provided. The SVN has the fundamentals of a gird already working in test...

My best advice (for a short-term fix) would be to study the workings of Table and extend and change the issue behaviour - I'd guess it wouldn't be that hard.

pillindra
1 Jul 2008, 1:05 PM
Thank you for your reply. That helps. I will look in to modifying it.

Padma