Amend sort order depending on what link is clicked

Ok, first off newbie here

I have put tablesorter into a site i am building and everything works perfectly…the default sort i have is on the 3rd column. What i would like though is for the default sort to be depended on what link they have clicked from another page

Examples:

User is one Page 1 - clicks Link 1 - taken to tablesorter page with table sorted via column 1
User is one Page 1 - clicks Link 2 - taken to tablesorter page with table sorted via column 2
User is one Page 1 - clicks Link 3 - taken to tablesorter page with table sorted via column 3

The current default script i have is:

Also, my pages have been created in PHP

Hope somebody can help me

Thanks in advance

On that another page where you have link to page with tabel, you need to include column id in the link:

<a href="table_page.php?sort=1">Table sorted by column 1</a> <a href="table_page.php?sort=2">Table sorted by column 2</a> <a href="table_page.php?sort=3">Table sorted by column 3</a>
and on your page with table, add this sort value to your jquery code:
[php]

[/php]

Thats great - thank you very much

It kind of works - but always sorts by column 2 (sector)

If i show you a live example it may help
http://ianpulfer.net/st/projects.php

I have put the code on there and within (St Leonard’s Mental Health Unit)
http://ianpulfer.net/st/project_06.php
the text at the top (project/sector/date) is where the links are…

Also, i think column 1 is 0, 2 is 1, 3 is 2 - if that helps?

Thanks in advance again

Actually ignore that - it works fine…was looking “offline” :-[

How do i set it so it sorts A-Z instead of Z-A though :smiley:

I guess you need to add this option to your tablesorter:
sortInitialOrder: “desc”

but you need to refer to documentation of this jquery plugin.

Hiya

It was pretty simple - the 1 at the end of the code means it sorts Z-A and if it is a 0 then that’ll make it A-Z

But here’s my (final) question :slight_smile:

Here’s the code (below) you gave, if i wanted it sorted:

A-Z (0) when a user comes from table_page.php?sort=1
A-Z (0) when a user comes from table_page.php?sort=2
BUT
Z-A (1) when a user comes from table_page.php?sort=3

I’m guessing where the ‘1’ part is at the end needs to have some kind of code similar to how you have done the first part?

Promise this is my final question

Answer:
[php]$("#myTable").tablesorter( {sortList: [[<?php echo (isset($_REQUEST['sort']) and in_array($_REQUEST['sort'],array(1,2,3)))?($_REQUEST['sort']-1):'2' ?>,<?php echo $_REQUEST['sort']==3?'1':'0' ?>]]} );[/php]

Thank you so so much

Its actually inspired me to learn all this ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service