TableSorter limiting (sorting) one page at a time?

I see that in the tableSorter, you can sort one page at a time, as far as I am concerned.

Can only one page of results be sorted at a time? Which is quite limiting. If you have a query result that spans multiple pages, how do you handle this?

If anyone knows better, feel free to correct me if I am wrong

Thanks.

+2


a source to share


2 answers


I would assign an id for th in thead to the table that matches you columns in the SQL table.

$("table thead th").click(function(){
    $.getJSON('ajax/get_results.php', 
        {sortby: $(this).attr('id')},
        function(data) {
            $.each(data, function(){
                // fill table here
            }
        });   
});

      

You can create some function to sort the table, which you can also use to modify the page using AJAX if you haven't already.

And to the backend then sort using SQL

"SELECT * FROM table ORDER BY ".$_GET['sortby']

      

Of course, you have to provide this sorting, for example, filter it using an array of allowed values. I would suggest creating an array with allowed column collation names and use array_intersect () to filter out only valid values, or just check with



if(isset($allowed_columns[$_GET['sortby']]))

      

Then just output the whole thing to JSON, putting all the results into an array, and then:

echo json_encode($array_with_results);

      

I think you would like to output something like this in JSON:

{
  {col1: 'row1',col2: 'row1',col3: 'row1'},
  {col1: 'row2',col2: 'row2',col3: 'row2'},
  {col1: 'row3',col2: 'row3',col3: 'row3'}
}

      

+2


a source


I came across this post while looking for a solution to the same problem.
(I know this is an old post, but I have an answer that might help people having the same problem, or even you)

Take a look at this plugin: "tablesorter pager" , it allows you to put the pager at the top of the sorted "tablesorter" table.
I though it might be helpful.



Enjoy ¯ \ _ (ツ) _ / ¯

+2


a source







All Articles