novacara
novacara

Reputation: 2257

Using JQuery Tablesorter to sort Gridview with Textbox elements

I am trying to use the jQuery tablesorter to sort through a gridview of mine. Most of the columns in the gridview contain textboxes, some checkboxes, and some regular text.The tablesorter seems to just sort regular text by default. Since I have very little jQuery experience could someone familiar with the tablesorter help me understand what I need to do to get the tablesorter to sort columns with textbox data as well as those with just plain text?

EDIT with Code

<script src="../scripts/jquery-1.7.min.js" type="text/javascript"></script>
<script src="../scripts/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("parts_gv").tablesorter({
            textExtraction: function (elem) {
                var $input = $(elem).find("input[type=text]");
                if ($input.length > 0) {
                    return $input.val();
                }
                else {
                    return $(elem).text();
                }
            }
        });
    });
</script>

Upvotes: 1

Views: 1995

Answers (1)

Tomalak
Tomalak

Reputation: 338198

You need to define a custom text extraction function. It's not difficult:

$("table.sortable").tablesorter({ 
  textExtraction: function(elem) {
    var $input = $("input[type=text]", elem);

    return $input.val() || $(elem).text();
  }
});

Upvotes: 2

Related Questions