Link to home
Start Free TrialLog in
Avatar of James Rodgers
James RodgersFlag for Canada

asked on

Sort Table on Multiple Columns

I have a dynamically generated table/contents that i want to give the user the ability to sort on multiple columns, columns will not always be beside each other

Rep Name (multiple occurrennces) Building ID (Multiple occurences per rep) Building Name  Employee Name Job code

theer can be any number of fields and the user can sort on multiple field

so i give teh user a group of drop downs that lets tehm selet up to 5 fields on which to sort, i then pass teh column indexes to a function and dynamucally sort on those selections....

how?

TIA
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

The most people ask for multiple field sort without a moment to imagine when multiple fields sort makes sense.
My assumption is that all first four fields are unique, therefore you need NOT to sort for the first four fields when you also sort for the fifth field. Sort only the fifth field alone and you have the same sort order!

Your Rep, Building and Employee sorting is NOT a sorting but grouping. If you would sort for Employee names, then you can never maintain the building categories

Here a table sort example:
http://eeqp.com/stats/hof.html
The script behind the table is this:
http://eeqp.com/stats/zpSortHOF.js

The main part was designed by me and then extended by amebe, the QuickPost developer!
Avatar of dbritt
dbritt

See my old solution:

http:Q_21759382.html#16130456
Avatar of James Rodgers

ASKER

>>My assumption is that all first four fields are unique, therefore you need NOT to sort for the first four fields when you also sort for the fifth field. Sort only the fifth field alone and you have the same sort order!

would be true if the output could be sorted on the rep name when generated by the SQL, unfortunately, the source for all the data, other than the rep name, comes form an oracle server while the rep name is a local table on an SQL server and has to be matched up to the during the ouput loop, so i have base data sorted/ordered on the  building id which means teh rep info is not sequential
eg
REP                    Building         ............
Joe                     0036
Mike                   0099
steve                  0429
Joe                     0488
steve                  0489

so if the user want to see all of joes buildings together they need to sort it on joe, but at teh same time i would like to keep teh building order also so that it goes like
REP                    Building         ............
Joe                     0036
Joe                     0488
Mike                   0099
steve                  0429
steve                  0489

i did think this through, it's just that the way the data is gathered affects the final output, and needs to be sorted AFTER being displayed

>> i did think this through, it's just that the way the data is gathered affects the final output, and needs to be sorted AFTER being displayed

But it doesn't seem like you tried my solution that I linked you to above. Try it out, it should take care of what you need.
Does not the EE ranking list sort like you ask for?
http://eeqp.com/stats/hof.html

Look at that table and click on name column header labeled "Expert"
You will see my name second last in that alpha sort order.
Click then on RegDate column and you will see I am in the first row.
All the time my ranking 15 stay in my row.

yes, it is a sort, but i need it to sort on multiple columns
So you want the building numbers for Joes and Steves to be in ascending order in your upper example, right?

Zvonko, yes, i want to be able to identify specific columne on which to sort,
so i wan the table to sort on REpP, BUILDING, and other field(s)

dbritt, i am looking at yours and it doesn't seem to be doing anything
of course it does something, fill in some values and press "sort"...just use the multiSort function in the javascript for your table.
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gotcha!
:-)
Because the upper domain is no more accessible here the reference to the source on EE:
https://www.experts-exchange.com/questions/21425003/another-sorting-table-using-zvonko's-zpSortHOF-js-related-question.html