ThunD3eR
ThunD3eR

Reputation: 3456

How to apply tablesorter correctly?

I have been all over the place since yesterday to find a soloution for my problem. I have a table where i sort some of my colums and some i dont. One of these is a textboxinput where i use a parser. My problem then? Well the colums in the textboxes get sorted the first time i click on that row BUT they get sorrtet in the wrong order and then the second time i click on it to sort again it does not do anything.

I think this is weird and have started to check my other jquery files to see if i have anything that might be preventing this but I wanted to check if my code is correct and what better placce to do so then here.

I have been reading up on tablesorter from these links:

http://mottie.github.io/tablesorter/docs/example-parsers-advanced.html

http://tablesorter.com/docs/

http://tablesorter.com/docs/example-parsers.html

my code:

 // custom sorting of value in text input   
 $.tablesorter.addParser({
     id: 'input_text',
     is: function (s) {
            // return false so this parser is not auto detected  
            return false;
         },
         format: function (s) {
            return $(s).attr('value');
         },
         type: 'text'
     });
     // Tablesorter
      if ($(".attendanceList tbody tr").length > 0) {
           $(".attendanceList").tablesorter({ headers: { 
                 1: { sorter: false },
                 2: { sorter: 'input_text' },
                 3: { sorter: false },
                 4: { sorter: false },
                 5: { sorter: false },
                 6: { sorter: false },
                 7: { sorter: false },
                 8: { sorter: false },
                 9: { sorter: false },
                 10: { sorter: false}
           },
           sortList: [[2, 1], [0, 0]]
           });
 }

picture of my problem:

http://imageshack.us/photo/my-images/198/sorterprob.jpg/

EDIT:

I forgott to mention that the sort shall also be able to sort on letters not only numbers

Upvotes: 2

Views: 143

Answers (3)

ThunD3eR
ThunD3eR

Reputation: 3456

I solved this some time ago but forgott to update. The problem was that this code

return $(s).attr('value') 

gave me an undefined value so i changed it to:

return s

and the sorting worked.

Upvotes: 0

PSR
PSR

Reputation: 40358

$(".attendanceList").tablesorter({
     headers: {
        column Number: { sorter: 'digit' } 
     }
 });

Upvotes: 1

ilyes kooli
ilyes kooli

Reputation: 12053

change type: 'text' to type: 'numeric'

Upvotes: 0

Related Questions