21307 Posts in 5737 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 549 Views |
-
Alpha Sorting manymanycomplextablefield

4 September 2011 at 8:10am
Hi all,
In the ecommerce module I have products that appear on many pages.
The problem is when I am in the CMS and want to tick which other pages the product belongs to it's so messy because the pages are not listed alphabetically. I have over two hundred pages so I have to trawl through them to find the ones I need.
I've been toying with the code below from the Product.php file but cannot get the pages to appear by name (I'm guessing they have ordered themselves by page ID maybe)
Does anyone have any advice on how I can have these pages appear alphabetically in the Product Groups tab?
protected function getProductGroupsTable() {
$tableField = new ManyManyComplexTableField(
$this,
'ProductGroups',
'ProductGroup',
array(
'Title' => 'Product Group Page Title'
)
);$tableField->setPageSize(30);
$tableField->setPermissions(array());//TODO: use a tree structure for selecting groups
//$field = new TreeMultiselectField('ProductGroups','Product Groups','ProductGroup');return $tableField;
} -
Re: Alpha Sorting manymanycomplextablefield

4 September 2011 at 10:00am
You can do this two ways. One is to add a default sort to the ProductGroup class (something like public static $default_sort = '"Title"';)
The second way is to pass a sort argument to the ManyManyComplexTableField constructor. The constructor has the prototype function __construct($controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""), so something like:
$tableField = new ManyManyComplexTableField(
$this,
'ProductGroups',
'ProductGroup',
array(
'Title' => 'Product Group Page Title'
),
'', // filter
'"Title"' // sort
); -
Re: Alpha Sorting manymanycomplextablefield

5 September 2011 at 3:18am
Sweet
Thanks Simon.
I opted for your first suggestion and went with public static $default_sort = 'ParentID, "Title"';
This now groups my pages if they are subpages of their parent and then sorts them alphabetically.
The only thing is it doesn't group sub pages with their parent page or 3rd level pages with the 2nd level pages of the parent but I can live with that.I've also noticed that the pages that are checked to appear in other categories don't register with the resultsbar.
For instance I have 8 Products in 'example section'. 2 products are directly from the section while the other 6 are brought in using the ManyManyComplexTableField.
But the results bar says "Showing 1 to 8 of 2 Products"Any idea how I can stop the resultsbar ignoring the extra pages in its count?
| 549 Views | ||
|
Page:
1
|
Go to Top |

