Sort RG by column headers

I have searched the forum for the answer to this on the forum and I have found some partial answers but can’t seem to get a solution that works.

I want to be able to click on a header text item (e.g. due date) and sort the RG beneath by the data for that column. I understand that the answer is to use ‘which field’ in the sort and set this to a specific value stored in a ‘state’ but I haven’t been able to get this to work.

Should I be looking at doing this in the Conditional tab or on the Appearance tab? Does it matter if I have constraints configured?

If someone could point me at a working example that would be great.

Just a point to note I tried to do the sort by using a value in an input field as a test and I couldn’t get this to work!!

Thanks

D

Hello @dunnydf

@pablo.heredia ’s tutorial may help here :smiley:

1 Like

Thankyou - he uses a plugin or creates another field on the DB to for the sort which is a bit different to what I want to do. I am sure there is a way to do this with setting states but I just can’t quite work it out.

EDIT - I have it partly working in that I have created a state on the header row group and I populate this state with the appropriate field name when I click text field in the header. This works but I now need to work out how I can click it asecond time and reverse the sort order.

EDIT 2 - I have it working by using 3 states including one that is a counter. I use modulo on the counter and increment it each time the text is clicked. I can then switch the sort order around on each click. I think i will also need to set a state now for the filed name as this is hard coded temporarily. Downside is the number of states I will need to maintain in the page. Now I have the concept working though I might be able to sreamline it a little.

Regards

Hi!

If you don’t have dynamic columns why not use Option Sets. States are pretty hard to keep track of. Option Sets can be used anywhere in your app and easy to manage.

You can create an option set with a second field (text type). Display can be whatever you want it to be for your own reference and the text field must be the name of the field from the Thing you are listing in your RG.

When setting the “sort by” in ur data source, just use “Get an Option” and make sure to point to that Option’s text field (the field u created for the option set).

Thanks, good idea.