Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Alpha Sorting manymanycomplextablefield


Go to End


3 Posts   1104 Views

Avatar
ambient

Community Member, 130 Posts

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;
        }

Avatar
(deleted)

Community Member, 473 Posts

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
);

Avatar
ambient

Community Member, 130 Posts

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?