I have a table with a single column whose cells contain complex markup.

Let's say this markup contains a name and a price:

<div>
    <span class="item-name">Name</span>
    <span class="item-price">70</span>
</div>


I have external links that let you sort on name or price:            
                  

var sort_by = 'name';

 $('#sort-by-price').click(
                    function(){
                        sort_by = 'price';

                        $('#results').trigger('sorton', [[[0, 1]]]);
                        return false;
                    }
                );

I have a custom parser and data retriever:
                $.tablesorter.addParser({
                    // set a unique id
                    id: 'itemsort',
                    is: function(s) {
                        return true;
                    },
                    format: function(s) {
                        return s;
                    },
                    type: 'numeric'
                });

results.tablesorter({
                    headers: {
                        0: {
                            sorter:'hotelsort'
                        }
                    },
                    textExtraction: extractSortData
                });

        function extractSortData(n)
        {
            var node = $(n);
           
            if(sort_by == 'price')
            {
                return node.find('span.item-price').text();
            }
            else if(sort_by == 'name')
            {
                return 1 /* for the purposes of the example*/;
            }
        }


However, this parser is only called once when the tablesorter is
initialized, so regardless of the click the table is still sorted by
name not by price. How do I make tablesorter reparse the table with new
values?

Reply via email to