How to cycle sortby?

Discuss and share scripts and script files...
Post Reply
pleiades
Posts: 52
Joined: 13 Aug 2016 10:36

How to cycle sortby?

Post by pleiades »

Hello everyone,

I need a little help with what I'm trying to make, I like to cycle sort similar to the cycle through views on another thread.

I changed the cycle through view script to the sortby and sort but its not working.

Code: Select all

$mode = get("Sort");
    if ($mode == #321) {sortby "Created","a";}	
    elseif ($mode == #325) {sortby "Name","a";}
The script is trying to cycle between sort by created and sort by name.

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: How to cycle sortby?

Post by bdeshi »

get('sort') returns a string formatted as: "SortColumn[,Order]", such as

Code: Select all

Name,a
Custom 2,a
Can this be == to "#321" or any string like this? You need to compare a similar string.

Code: Select all

$sort = get("Sort");
    if ($sort == "Name,a") {sortby "Created","a";}   
    elseif ($sort == "Created,a") {sortby "Name","a";}
I'm just pointing you at the right direction. However, this will not work if sort is descending, even if sorted by Created or Name, because then $sort will end with ",d" instead of ",a", and the comparison will fail. You can use gettoken($sort, 1, ',') to get the sorted column, and gettoken($sort, 2, ',') to get the sort order. Then construct necessary comparisons using these values.
Hope this helps.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

pleiades
Posts: 52
Joined: 13 Aug 2016 10:36

Re: How to cycle sortby?

Post by pleiades »

Thank you SammaySarkar for your guidance, :tup: :tup: I was able to make it work, sort of. here is the code if anyone needs it.

The code cycles between Name and Created Column, if you want other column just add more case statement.

Code: Select all

	$sort = get("Sort");
 switch ($sort) {
   case "Name,a":
       sortby "Created","a";
       break;
   case "Name,d":
       sortby "Created","d";
       break;
   case "Created,a":
		sortby "Name","a";
		break;
   case "Created,d":
		sortby "Name","d";
		break;

Post Reply