# table column sorting problem

hi,

I have a problem with sorting of a table.

I don't know if one of you has already worked with this table sort. I am using the tablesort of http://tablesorter.com/docs/. It is working, but i having problems sorting columns with alpha-numeric data in it, columns us amount separators etc....

examples:

i am trying to sort for example numbers like "1,107,748.90" but it is not doing it right.
i am getting the following:

amount:

1,107,748.90
1,727.79
10,050.86

which is not good.
any idea where can i modify to get it right?

i also have a column with ABDA00364 as account number together with account numbers of only numbers. here too it is not sorting right.
i am getting the following:

account number:

510008123
5431100000
5588990000
5892655105
5892656101
630033456
7190057654
80783824
ABDA00364
ACCO00605

which is not good.
any idea where can i modify to get it right?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
It looks like all you data is being sorted as TEXT rather than NUMERIC. A quick look at the tablesorter docs indicates that you can create a parser that will let you change how sorting is done ( http://tablesorter.com/docs/example-parsers.html ).

For the numbers, the parser would just need to convert the values to numbers (strip commas, use parseFloat() to convert the result a number).

For the accounts, I'm going to guess that front padding with zeros or maybe spaces to a fixed length will give you the results you want.

0
Author Commented:
do you maybe have a code sample on how to?
0
Commented:
Note, I haven't actually used the tablesorter tool, but this would be my first guess based on the docs.

I'm assuming you have two columns, account and balance, and that the account numbers are in the account column and the numbers are in the balance column.
// set a unique id
id: 'account',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
for ( ; s.length < 10; ) {
s = "0"+s;
}
return s;
},
// set type, either numeric or text
type: 'text'
});

// set a unique id
id: 'balance',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return parseFloat(s.replace(/,/g, ""));
},
// set type, either numeric or text
type: 'numeric'
});

\$(function() {
\$("table").tablesorter({
1: {
sorter:'account'
}
2: {
sorter:'balance'
}
}
});
});
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
hi SordSord,
i am going to test this out.

i also have another table sorting code which i am having problems with. is it possible for you to take a look at it?