3.2.0

multi-column sorting

Is there any way to specify multi column sorting ie sorting of a column based on sorted form of another column.
sweety
January 10,
Sir
If possible Please Help me
how to drag listbox items within the same listbbox(to move up and down).using Javascript.

Thanks a lot.
Anand
January 13,
To illustrate the multi-column sorting,
Say, here is a three columns of unsorted data

col1 col2 col3
B 2 X
B 1 Y
A 3 Z
A 3 M

Is it possible to specify sorting on col1 first and then sorting on col2 to produce such sorted result, as below?

col1 col2 col3
A 3 M
A 3 Z
B 1 Y
B 2 X

Thanks a lot!
Nick
January 18,
Hmm, maybe you could have a hidden col4 that uses the formula of col1 plus col2. Then you could sort on col4.

Just a quick thought... that would work in Excel.
Rob Francis
January 18,
Or what you might try is to have myData with 5 columns but only displays the first 3 columns like:

column
1 2 3 4 5

A 3 M 1 3
B 1 Y 2 1

Code:
myData = [ ["A","3","M","1","3"], [....]....]
....
obj.setColumnProperty("count", 3);

where 4 is numerical representation of column 1. And add 4+5 together becomes the string 13, 21 for sorting

Hope it helps.
flashsnake
August 1,
Exactly that flashsnake !!

I have implemented multi column sorting and it works perfectly fine.

I just followed the approach that library is using.

Thanks
Vikramaditya Garg
Vikramaditya Garg
August 3,
multi column sorting is slightly worrying.It takes abt 366 calls to comparator for just 44 records in xml.This takes abt 1.5-2 seconds and if record count increases more and more the call to comparator increases considerably.

Thus multilcolumn soring decreases the overall performance.

Thanks
Vikramaditya Garg
Vikramaditya Garg
October 9,
Hi Vikram,
could i have a litttile more light on the multi column sorting.
anand
March 13,
Multi-column sorting is easy to do if your sort algorithm is stable, meaning that if items a and b compare as equal, their positions relative to each other doesn't change.

IE appears to use a stable sorting algorithm, while Firefox does not. Since ECMA script does not guarantee stable sorting (and Mozilla versions since 2003 do not sort this way: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:sort), you must create your own stable sorting algorithm for use in Mozilla. An IE targetted app can still use the sort abstraction/overload and just let it pass through.

The comment above about creating a hybrid column to contain sort keys is good, but it does not allow multiple sorts with different directions. For instance, if you have some method of scoring your objects, but want to honor the delivery order, you would want to sort your list in descending order by score and ascending order by date received. You can't easily create a hybrid key to accomplish this.

You could; however, sort your list of objects in ascending order by date, iterate through your object table assigning a sort key that includes a padded decending number suffixed to your padded score. That hybrid key, when sorted in descending order, would provide the proper order.

See why stable sorts are nice?
J.D. Pace
April 17,

This topic is archived.

See also:


Back to support forum