# Sort asc and desc on alternate clicks of a button

**URL:** <https://forum.servoy.com/t/sort-asc-and-desc-on-alternate-clicks-of-a-button/5377>\
**Category:** Classic Servoy\
**Created:** [January 21, 2006, 9:48am UTC](https://forum.servoy.com/t/sort-asc-and-desc-on-alternate-clicks-of-a-button/5377 "2006-01-21T09:48:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Aykroyd](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@Jan\_Aykroyd](https://forum.servoy.com/u/Jan_Aykroyd)\
**Post date:** [January 21, 2006, 9:48am UTC](https://forum.servoy.com/t/sort-asc-and-desc-on-alternate-clicks-of-a-button/5377/1 "2006-01-21T09:48:00Z")

</div>

Hello there

I have a simple list of items with buttons at the head of each column with methods attached so you can sort by that particular column. Not being a whizz at Servoy just yet, I would like to know how to have it sort the column in ascending and descending order on alternate clicks of said buttons. Is this possible?

Any help much appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [January 21, 2006, 11:19am UTC](https://forum.servoy.com/t/sort-asc-and-desc-on-alternate-clicks-of-a-button/5377/2 "2006-01-21T11:19:43Z")

</div>

Look in the Servoy menus for the sort command. In the dialog box there is a button to “Copy” the sort string.

Create a script. Add a controller.sort() and paste in the sort string. I think it needs quotes.

You will need one to sort ASC and one DESC…

---

<div class="post-metadata">

**Author:** ![Jan\_Aykroyd](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@Jan\_Aykroyd](https://forum.servoy.com/u/Jan_Aykroyd)\
**Post date:** [January 25, 2006, 9:49pm UTC](https://forum.servoy.com/t/sort-asc-and-desc-on-alternate-clicks-of-a-button/5377/3 "2006-01-25T21:49:35Z")

</div>

Many thanks for your reply. Once I’ve created the scripts, how do I apply them to the button so it sorts asc/desc on alternate clicks?

---

<div class="post-metadata">

**Author:** ![grahamg](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@grahamg](https://forum.servoy.com/u/grahamg)\
**Post date:** [January 26, 2006, 12:06am UTC](https://forum.servoy.com/t/sort-asc-and-desc-on-alternate-clicks-of-a-button/5377/4 "2006-01-26T00:06:00Z")

</div>

You could set up a Global field gColSort then:

if (gColSort)  
{  
sort ‘fieldname asc’  
gColSort = null  
}  
else  
{  
sort ‘fieldname desc’  
gColSort = 1  
}

Warning: pseudo code as haven’t got Servoy open but should get you started

Graham Greensall  
Worxinfo Ltd
