Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Alpha Sorting manymanycomplextablefield

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

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

Page: 1
Go to End
Author Topic: 668 Views
  • ambient
    Avatar
    Community Member
    113 Posts

    Alpha Sorting manymanycomplextablefield Link to this post

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

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: Alpha Sorting manymanycomplextablefield Link to this post

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

  • ambient
    Avatar
    Community Member
    113 Posts

    Re: Alpha Sorting manymanycomplextablefield Link to this post

    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?

    668 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.