Printable version XML version
Login
Name

Password


Join
Forgot your password?
erp5.org => wiki.erp5.org !

erp5.org has permanently moved to wiki.erp5.org !

Current status of ERP5 community websites:

  • www.erp5.org should redirect to wiki.erp5.org automaticcaly.
  • wiki.erp5.org is the place where fresh news and documentation are published.
  • cps.erp5.org is the old erp5 community website.

Note: if you created content in this ancient portal, please migrate it to the wiki. The old website will stay online as long as all contents are not mograted to the wiki.

Sorted Listboxes
This document will show you how to set your listboxes in order to be able to see them in a orderable way. It's very easy to set up some order, and, badly, often this feature is not used so much. So, thanks to this document, everyone will know that this is very easy and will use it a lot !

ListBox sort parameters:

Sortable Columns:

There is two fields in the listbox related to the sort. The first one is Sortable Columns. It defines wich columns are sortable. You can enter it like this :

      title | Title
      description | Description

The only important information is the left part. The right part is not used at all. The left part must be exactly the same as the left part of the field Columns of the listbox.

This field is not required, most of the time you can forget it. Indeed, if nothing is defined here, then it will takes values of "Searchable Columns", and if nothing is defined in "Searchable Columns", then the lisbox will look at mysql tables if he can find one table with the right column.

Sortable Columns and MySQL:

With MySQL, the only important thing to setup is to enter correctly the field "Columns". When you use MySQL queries, through portal_catalog or searchFolder for example, you MUST set the left part of columns with the value of the column id. This is a bad way of doing for the field "Columns" :

      getTitle | Title
      getDescription | Description
      getWhateverIsNotInTables | Something

In the table catalog, we have a column called title, but this does not match getTitle, so by default, the title will not be sortable.

This is the right way of doing :

      title | Title
      description | Description
      getWhateverIsNotInTables | Something

In the table catalog, we have a column called title, this matches title, so by default, the title will be sortable. So, automatically, the title and the description will be sortables, not the last column.

Default Sort:

The second field related to sort is called "Default Sort". It defines the default sort used, for example you may want to sort by portal type and for all objets with the same portal type, you may want to sort by title. You can define this field like this:

      portal_type | ascending
      title | descending

Again, the left part is exactly like the left part of the field "Columns". The right part defines if you want to order in ascending or descending way. If you put something else than ascending or descending, then the ascending way will be automatically choosen.

Don't forget that the default sort is stored in your selection. So if you change a listbox that you already used, then the new default sort will not be used. You have to reset your selection if you want to see the default sort, the one associated with the selection name of the listbox.

Once you defined the default sort, then the list method of the listbox will be called with a parameter sort_on. In our example, sort_on is like this:

      (('portal_type','ascending'),('title','descending'))

The sort_on parameter is a list of couples. The support if the sort_on parameter already exists in the catalog. It can handle the sort on several columns ordered in a different way. If you don't use the catalog, let's say that you use a script, then you need to modify your script so that it will be able to use the sort_on parameter.

Conclusion :

It is very simple to set sort parameters on listboxes. First, most of the time you don't need to define the field Sortable Columns. Next, when you use the catalog, you have nothing to do except define nicely the "Default Sort" field.

Relation field and search:

By the way, it's also possible to define the sort used to display a list of choice with a relation field, when you are redirected to the listbox of "Base_viewRelatedObjectList". Indeed, on all relation fields, there is a field "Default Sort" that will be used by the listbox of Base_viewRelatedObjectList. You can notice that you can also define the columns and some parameters.


(c) 2001-2004 ERP5 Foundation
www.erp5.org
All Content Published Under Free Licenses
Powered by ERP5 Open Source ERP, Zope, CPS and Nexedi