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.

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

Model Admin - so many questions, so little documentation

Go to End

18 Posts   10468 Views

Design City

38 Posts

8 June 2009 at 6:30pm

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


Community Member, 145 Posts

8 June 2009 at 7:25pm


> 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.
Patches welcome


Community Member, 11 Posts

12 August 2010 at 12:06am

Edited: 12/08/2010 12:07am

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(

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.


Forum Moderator, 1899 Posts

12 August 2010 at 12:25am

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


Community Member, 11 Posts

12 August 2010 at 12:36am

Edited: 12/08/2010 12:39am

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.


Forum Moderator, 1899 Posts

12 August 2010 at 12:51am

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.


Community Member, 11 Posts

12 August 2010 at 1:04am

Edited: 12/08/2010 1:04am

Do you know any other way than using default_sort?

I've read an answer from this thread

>> 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.


Forum Moderator, 1899 Posts

12 August 2010 at 9:12pm

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.