ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Sort number on header displaying wrong value

Open bjdash opened this issue 11 years ago • 6 comments

When I sort a column by clicking on headers 1 is displayed to indicate sort order. Shift clicking on another column and 2 on that. Now if I continue to shift click on first column that I sorted earlier (marked with label 1), after one click 1 is removed and after another click it is labeled with 3. Now I have two columns labeled 2 and 3 while 1 is missing.

One would expect that it should retain the number or decrease the other numbers by 1 before adding a label.

bjdash avatar Nov 06 '15 11:11 bjdash

Can you please make a plunkr that shows this behaviour?

imbalind avatar Nov 06 '15 18:11 imbalind

Here it is http://plnkr.co/edit/i4HRAaLr9RhkwWM5ZTWc?p=preview. I am using the same example from the ui-grid tutorial.

To replicate the issue sort the table by 'Gender', now shift click on "Name" to sort it. At this stage 'Gender' is tagged 1 and 'Name' is tagged 2. Now try to sort "Gender" again but do it by holding Shift. After few clicks "Gender" will be tagged 3 and there is no 1.

Also if you continue Shift clicking 'Name' it will get 4.

bjdash avatar Nov 07 '15 21:11 bjdash

The problem seems to be function getNextColumnSortPriority at Grid.js.

This function now looks for the greatest column priority and then returns that value + 1.

A better version would find the least unused priority.

A further improvement would be to edit sortColumn function and lower the priority af any previously prioritized column whose value was higher then the one the user edited.

imbalind avatar Nov 08 '15 23:11 imbalind

Is there any word when this is will be fixed, beacuse I am using it and I have a defect logged for this.

bjdash avatar Nov 12 '15 10:11 bjdash

problem still exists -- even on the UI Grid home page

on the basic example grid . Use the arrow menu on the "Name" column Set it to Sort Ascending

Use the arrow menu on the "Gender" column Set it to Sort Descending

Use the arrow menu on the "Name" column Set it to Sort Descending. Notice the count is incremented incorrectly. It is easy to really mess up the internal accounting by playing with the sort directions on multiple columns

hint : if you have only one number to work with , then refactor the code to use a sign ( + or - ) and the priority to designate sort and priority.

hence a sortState of { Gender: -3 } implies that the Gender column is the third priority field to be sorted in a descending order.

Of course removing sorted columns mean you have to do accounting and rework the numbers ( column.sort.priority I think it is? )

mattmutt avatar Feb 18 '16 10:02 mattmutt

Yes, @mattmutt there's a ticket for the column.sort.priority recalculation out there too: https://github.com/angular-ui/ui-grid/issues/4196

meyerds avatar Mar 01 '16 20:03 meyerds