Jump to:

23473 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Model Admin - so many questions, so little documentation

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 2 3
Go to End
Author Topic: 7984 Views
  • DesignCity
    Avatar
    38 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    Great stuff, thanks Ingo!

    Re: $allowed_actions
    I've got a site that has a few hundred pieces of data that need to be updated but must not be deletable. Previously I've used a CTF for this since it allows for permissions to be set for actions like edit, add etc. There may already be a solution I'm not aware of...

    Also: is there a way to have the full table appear on page load (as if you pressed search with no filters selected)? I don't think we got an answer to that one, but I'm a little food-deprived right now, so excuse me if we did! ;)

  • AdamJ
    Avatar
    Community Member
    145 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    DesignCity:

    > I'd like to put in a request for more information on how to automatically load an unconstrained search result when a ModelAdmin tab opens as well.

    http://open.silverstripe.com/ticket/3693
    Patches welcome

  • EzraNaj
    Avatar
    Community Member
    11 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    Hi guys,

    I'm new to Silverstripe. How do you sort search results in ModelAdmin?
    I tried using DataObject::default_sort. It worked. However I want to sort two columns in ASC order.
    These columns are 'CategoryName' and 'ProductName'.

    Category.Name is a db field of Class Category while ProductName is a db field of Class Product.

    Product "has_one" relationship with Category
    >>static $has_one = array('Category')

    while Category "has_many" relationship with Product.
    >>static $has_many = array('Product')

    Under Product Admin :

    static $summary_fields = array(
             'Category.Name',
             'Name');

    static $default_sort = "Name ASC"; This worked fine. Product Names are ordered alphabetically

    I wanted to sort first Category Names then sort Product Names so

    static $default_sort = "Category.Name, Name ASC"; This caused an error saying "Unknown column 'Category.Name' in 'order clause'"

    Please help. Ive been pulling my hair out trying to solve this.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    how about adding the default sort to the Category DataObject on Name? Then maybe the DataObject will use both?

    p.s. ModelAdmin Improvements attached to this ticket for auto searching and a better way to display models in a select element
    http://open.silverstripe.org/ticket/5665

  • EzraNaj
    Avatar
    Community Member
    11 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    I actually have an admin for Category which list all category names. I forgot to mention that I already also have added the default sort to Category DataObject. The default sort worked and listed category names alphabetically.

    I have another admin for Product. Under this admin, this displays CategoryName and Product Name columns and I wanted them to display in an alphabetical order. I wanted category Names ordered first alphabetically then Product Names also ordered alphabetically.

    Product dataObject didn't use both default sort. I tried static $default_sort = "Name ASC"; on Product. It ignored default sort of Category. So the table displays Product Name column alphabetically while Category Name column was unordered.

    Thank you so much for the reply. I still need help.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    I don't want to be all doom and gloom - but I just debugged SQLQuery sql() and for a similarly retrieved ModelAdmin of mine I can see it retrieving the first rows of the managed object first (by their default sort) and then another set of select for the relating dataobject for the summary fields... my conclusion you are not going to get a result using default_sort - I'd stop now if I were you - sorry.

  • EzraNaj
    Avatar
    Community Member
    11 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    Do you know any other way than using default_sort?

    I've read an answer from this thread http://ssorg.bigbird.silverstripe.com/general-questions/reply/255859

    ====
    >> Is there a way to sort the search results in the TableListField or to have it appear on opening the page?

    It uses DataObject::$default_sort. You can overload ModelAdmin->getResultsTable() and ModelAdmin->getCustomQuery() for any custom sorting. "

    ===

    I tried overloading ModelAdmin->getResultsTable() but I did'nt really have any idea and I just got lost.
    Thank you so much.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    I have looked at that because I need to do some very custom searching for someone, but I am hoping I can avoid it as even after it was explained a bit to me I am still scratching my head how to achieve what I want with it... sorry I cannot be more help... but please post back when you find a solution.

    7984 Views
Page: 1 2 3
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.