views:

101

answers:

2

Hello,

I work with jquery tablesorter to display music charts. So i have some columns with artist - song - chart position.

The column chart position contains mainly numbers; but when a song is not listed in the chart is gets the value "-". This creates a sorting problem when i want to sort the column, because the values "-" will be sorted above the numbers.

I get this Michael Jackson Human Nature - Michael Jackson Thriller 1 Michael Jackson Bad 2

But i want first the numbers and sort like this: Michael Jackson Thriller 1 Michael Jackson Bad 2 Michael Jackson Human Nature -

Can somebody help me ? Has it something to do with the datatypes; i use now varchar.

Thanks

+1  A: 

You could try adding your own parser, like in the example here.

In your parser you could modify the value that is passed to tablesorter - and if the value is "-" (if it's your only problem), you could set it to, lets say, 999999. Dirty, fast hack, but it's what comes to my mind and what I would do.

Then, like in your example, you should set the type to numeric, so the numbers are sorted well.

kender
A: 

Thanks, i got it ! Here is the code i want to share too; a bit complexer because i work with the pager, zebra-effects and multiple charts position from other countries:

$("#myTable")
.tablesorter({ headers: {3: {sorter:'charts'},4: {sorter:'charts'},5: {sorter:'charts'}
,widthFixed: true, widgets: ['zebra'] } })
.tablesorterPager({ container: $("#pager"), positionFixed: false }); 
});
DaveL