0

I am using the code here to sort my table. The code and plugin work great but some of my <td>'s have <input> tags with values corresponding to the user who's row it is. The sorting system will not work will the <input>'s value. Been working on this for awhile and figured I'd ask on here how to get the sorting to look at the input values too.

var table = $('#user-table');
$('.sort-id, .sort-username, .sort-lastname, .sort-firstname')
.wrapInner('<span title="sort this column"/>')
.each(function(){

    var th = $(this),
        thIndex = th.index(),
        inverse = false;

    th.click(function(){

        table.find('td').filter(function(){

            return $(this).index() === thIndex;

        }).sortElements(function(a, b){

            if( $.text([a]) == $.text([b]) )
                return 0;

            return $.text([a]) > $.text([b]) ?
                inverse ? -1 : 1
                : inverse ? 1 : -1;

        }, function(){

            // parentNode is the element we want to move
            return this.parentNode;

        });

        inverse = !inverse;

    });

});
Community
  • 1
  • 1
Taylor Foster
  • 1,103
  • 1
  • 11
  • 24

1 Answers1

0

You want something like this......

table.find('td input').filter(function()

and then get the values of the inputs like so

return $(a).attr('value') > $(b).attr('value')

and also change the parent to move

return this.parentNode.parentNode;

http://jsfiddle.net/gFzCk/2998/

Shakawkaw
  • 341
  • 1
  • 11