Problems, need help? Have a tip or advice? Post it here.
11 posts Page 1 of 2
Hi I have two questions,

First, is it possible to have a sort button that users can click on to change the sorting of a list of pages by date, title, etc.?

Second, how would I make sure that the sorting of a alpha-numeric field is sorted properly?

Right now I get it sorted like this:

A-1
A-10
A-2

Instead of this:

A-1
A-2
A-10

Thanks!
Hi,

I'll assume you have the admin-panel in mind for both the questions.

First, is it possible to have a sort button that users can click on to change the sorting of a list of pages by date, title, etc.?
In the current version, I'm afraid, no. This will be available in the next version though.

Second, how would I make sure that the sorting of a alpha-numeric field is sorted properly?
Not to put too fine a point on it but, the sorting you get *is* the correct 'alphanumeric' sorting. What you actually wish is 'natural' sorting (http://www.copterlabs.com/blog/natural- ... -in-mysql/). Unfortunately, for now it is not possible. In the coming version we'd be able to tweak the SQL query to make this sort happen.
KK wrote: I'll assume you have the admin-panel in mind for both the questions.


Actually, I was looking for the front-end on these :)

And ya natural sorting is what I was hoping for! No worries on that one, thought I'd ask just in case. For now I just switched to using A-01 instead of A-1.

But for allowing users on the front-end to change the sort of the list of pages would be very useful! I have a list of items for sale and need them to be able to sort based on date or price. Is there a way I can force some extra javascript or php in there to make it happen?
On the front-end, it is totally up to you to implement the sort logic as you desire.

The cms:pages tag supports 'orderby' and 'order' parameters - you can set these dynamically to get the sorting done. For an example, please see http://www.couchcms.com/docs/advanced-t ... -view.html
KK wrote: On the front-end, it is totally up to you to implement the sort logic as you desire.

The cms:pages tag supports 'orderby' and 'order' parameters - you can set these dynamically to get the sorting done. For an example, please see http://www.couchcms.com/docs/advanced-t ... -view.html


Just took a quick look and it looks like that's what I need!

Thanks KK your awesome!
Okay so I have all the code in place that the tutorial went over but the sorting is not working. The query string is placed in the URL but the pages are in the same order.

Could it be that this does not work with pretty URLs enabled?

[EDIT] Nevermind, I figured that part out.. It wasn't liking the <cms:else_if> that the tutorial used, so I did nested if's instead. I guess tutorial uses a newer version.

Still having some problems though... It doesn't seem to like me sorting by k_page_date right now.

That and now I found another field I need natural sort for so I guess I'm just out of luck on that one as it's a price field.
Hi,

To debug, please explicitly specify the order fields in cms:pages e.g.
<cms:pages orderby='publish_date' order='desc'>

For a list of all values accepted by the 'orderby' parameter please see http://www.couchcms.com/docs/tags-reference/pages.html

Once you are sure it is working, replace the literal strings with variables. If now it does not work, print out the variables to see if their values match the ones we had explicitly used above.

Hope it helps.
Per the documentation on the editable tag:
search_type parameter determines how the values contained within an editable region are sorted and compared
Set search_type='decimal' on your price field and it should sort numerically instead of alphabetically.
KK wrote: Hi,

To debug, please explicitly specify the order fields in cms:pages e.g.
<cms:pages orderby='publish_date' order='desc'>

For a list of all values accepted by the 'orderby' parameter please see http://www.couchcms.com/docs/tags-reference/pages.html

Once you are sure it is working, replace the literal strings with variables. If now it does not work, print out the variables to see if their values match the ones we had explicitly used above.

Hope it helps.


Haven't tried this yet but I noticed that you used "publish_date" in your example instead of the "k_page_date" that I mentioned. What's the difference here? I'm guessing that using publish_date might solve my problem.

cheesypoof wrote: Per the documentation on the editable tag:
search_type parameter determines how the values contained within an editable region are sorted and compared
Set search_type='decimal' on your price field and it should sort numerically instead of alphabetically.


Thanks cheesypoof! I ended up doing this and it worked great! The only issue I had was that it no longer formatted with a comma if it was in the thousands so I just added a bit of jquery on the front-end side to format it for display so it works great now! Thanks!
When outputting the value on the front end use the number_format tag.
11 posts Page 1 of 2
cron