Single Click Sorting

9 posts by 3 authors in: Forums > CMS Builder
Last Post: May 3, 2010   (RSS)

By mark99 - April 29, 2010 - edited: April 29, 2010

Here's a quick question.

I have my list of products (records) being output on the list viewer PHP page but what I'd really like to do is offer the ability to quickly order key fields in Ascending or Descending order. Most of my competitors do this in a simple way by offering a clickable title (i.e. "Name", "Price" etc.) and when you click that once it re-orders the list to the opposite of the default order. So if I click the "Price" heading then suddenly all the records order by lowest price first, click it again and it orders by most expensive first etc.

Since CMS Builder is really a clever MySQL interface then this should be possible but I can't find a simple solution and PHP isn't my strong point lol.

Re: [mark99] Single Click Sorting

By zip222 - April 29, 2010

You might want to consider using javascript/jquery for this...

here is one option:
http://tablesorter.com/docs/

Re: [mark99] Single Click Sorting

By Jason - April 29, 2010

Hi,

We can definitely do this, and it only takes a little bit of PHP.

This code creates a single link. Use this for each of your column headers that you would want to sort by.
<a href="*YOURPAGE*.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="*FIELD*")? "*FIELD*" : "*FIELD* DESC" ?>">*FIELD LABEL*</a>

In this code, replace *YOURPAGE* with the name of the php page you're working with, *FIELD* with the database field you're wanting to sort on and *FIELD LABEL* with the name of the column. So, for example, if I wanted to sort by a products record number, it would look like this:

<a href="productsList.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="num")? "num" : "num DESC" ?>">Record Number</a>

Give that a try and let me know if it works for you. If it doesn't, maybe attach the page you're working with and I'll take a look at it for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Single Click Sorting

By mark99 - April 30, 2010 - edited: April 30, 2010

Yes that would work but for one big problem.

For some reason I found that CMS Builder didn't autmatically apply alphanumeric ordering to title field records so I was forced to set an orderBy in the "LOAD RECORDS" call at the top as follows:

'orderBy' => 'title ASC'

This of course causes me problems because it..

1) Screws up the output of _min and _max in search forms by always prioritising the title field ordering

2) Overides any orberBy I might try to force in a URL call.

How can I solve this so that my list output defaults to title ordering but allows me to change that in the URL?

I tried to set sorting to 'title ASC' in the admincp but it had no affect on the listing output (ED: I tried to put "dragSortOrder, title ASC" but no affect).

Re: [mark99] Single Click Sorting

By Jason - April 30, 2010

Hi,

Do you use "dragSortOrder" in the section editor, or have you removed that?

If you could attach the page you're working with, I can take a look at it for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [mark99] Single Click Sorting

By Jason - April 30, 2010

Hi,

You can get rid of dragSortOrder sorting by removing it from the "Listpage Fields" and "Sorting" sections of the section editor (note: remove it from both places before "Saving Changes")

Other than that, you can email me the file if you like to jason@interactivetools.com and I'll take a look at it.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Single Click Sorting

By mark99 - May 2, 2010 - edited: May 2, 2010

Yes but does that mean I will no longer be able to change the order of fields in the admin section editor?

This is essential, otherwise my data input will be literally messed up and randomly all over the place.
If I take it out then there seems to be no clear way of adding it back as the field itself does not specify its details.

Re: [mark99] Single Click Sorting

By Jason - May 3, 2010

Hi,

dragSortOrder is just for sorting records. You can remove dragSortOrder and still be able to organize your fields however you wish.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/