...

View Full Version : custom sort order



goofball1980
12-31-2010, 02:49 PM
Hi I have a table that sorts in jquery and I have one column that I would like to always remain the same while the other columns sort around it. What I want is for the order of the column to always be Great, Bad, Failure while every other column can be sorted and I don't want to the column to sort alphabetically. What is the easiert way for me to do this?

jmrker
12-31-2010, 04:33 PM
I'm a bit confused about your request.

Can you provide an brief example of what the display should look like before and after sort?

goofball1980
01-01-2011, 03:08 AM
an example would be:

Fruit Color Shape
---------------------------------
banana yellow long
orange orange round
apple red round
grape purple round
pear green oval

What I would want to be able to do is keep the shape column the way it is but have all of the others be sortable so that apple, orange, and grape could be sorted alphabetically in the fruit and color columns but in the shape column it would always be long, round, oval.

jmrker
01-01-2011, 04:18 AM
an example would be:

Fruit Color Shape
---------------------------------
banana yellow long
orange orange round
apple red round
grape purple round
pear green oval

What I would want to be able to do is keep the shape column the way it is but have all of the others be sortable so that apple, orange, and grape could be sorted alphabetically in the fruit and color columns but in the shape column it would always be long, round, oval.

I'm still having problems with the concept.
From your last post, if you sorted on fruit, you would expect?


Fruit Color Shape
---------------------------------
apple red long
banana yellow round
grape purple round
orange orange round
pear green oval

or if you sorted on color, you would get?


Fruit Color Shape
---------------------------------
pear green long
orange orange round
grape purple round
apple red round
banana yellow oval


Is that your idea?

goofball1980
01-02-2011, 03:04 AM
no if you sorted on fruit I would expect:



banana yellow long
apple red round
grape purple round
orange orange round
pear green oval

and for color:

banana yellow long
orange orange round
grape purple round
apple red round
pear green oval


would an array be the best thing to use?

jmrker
01-02-2011, 03:40 AM
no if you sorted on fruit I would expect:



banana yellow long
apple red round
grape purple round
orange orange round
pear green oval

and for color:

banana yellow long
orange orange round
grape purple round
apple red round
pear green oval


would an array be the best thing to use?
Why would a sort on fruit put "b"anana before "a"pple?
and sort on color put "y"ellow before "o"range?

I don't understand your definition of sort!

goofball1980
01-02-2011, 02:30 PM
A sort on fruit would put banana before apple because to maintain the order of the type column as long, round, oval banana would be first and the same for color

jmrker
01-02-2011, 03:21 PM
May not be as efficient as it could be,
as it is a very specific display order request,
but at least it does display a way to show a goofy kind of selected order non-sorted sort! :eek:


<!DOC HTML>
<html>
<head>
<title> Specific Ordered Sort </title>
<script type="text/javascript">

var Items = [
['banana','yellow','long'],
['orange','orange','round'],
['apple','red','round'],
['grape','purple','round'],
['pear','green','oval']
];

function display(order) {
var str = '';
var tarr = [];
for (var r=0; r<Items.length; r++) {
str = Items[r][order]+',';
str += Items[r].join(',');
tarr.push(str);
}
tarr.sort();
var tmp = [];
str = '<table border="1"';
str += '<tr><th>'+'Fruit,Color,Shape'.split(',').join('</th><th>')+'</th></tr>';
var Shapes = ['Long','Round','Oval'];
for (var i=0; i<Shapes.length; i++) {
for (var r=0; r<tarr.length; r++) {
tmp = tarr[r].split(',');
if (tmp[3].toLowerCase() == Shapes[i].toLowerCase()) {
tmp.shift();
str += '<tr><td>'+tmp.join('</td><td>')+'</td></tr>';
}
}
}
str += '</table>';
document.getElementById('display').innerHTML = str;
}

</script>

</head>
<body>
<select onchange="display(this.value)">
<option value="">Select order</option>
<option value="0">Fruits</option>
<option value="1">Color</option>
</select>
<div id="display"></div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum