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

How to add a custom filter in modeladmin?


Go to End


798 Views

Avatar
BenWu

Community Member, 97 Posts

22 January 2014 at 5:29am

I have got a class


class Product extends DataObject {
  static $many_many = array('categories'=>'Category');
}

and


class Category extends DataObject {
  static $belongs_many_many = array('categories'=>'Category' );
  static $has_one = array('Parent' =>'Category');
}

I would like to filter products by sub-categories only, If I put

 $searchable_fields = array('Categories.ID' ) 

in the Product class, i will have a dropdown box list all categories (including the Parent ones), which is messy