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, biapar, Willr, Ingo, swaiba

Start custom filter automatically


Go to End
Reply


364 Views

Avatar
Bereusei

Community Member, 94 Posts

19 September 2013 at 9:29pm

Hey guys,

in the backend of SS3 we have the nice filter function to search for special dataobjects in the listview.
In the modeladmin I´ve used a code which load values in the filter inputfields:

public function getSearchContext() {
	$currentUser = Member::currentUser()->FirstName;
	$currentUser = trim($currentUser);
		
	$context = parent::getSearchContext();
        $context->getFields()->fieldByName('q[Member__FirstName]')->setValue($currentUser); //set current user name in inputfield 'Member'
       
        return $context;
    }

This works pretty fine. What I now wanna do is to start the filter function automatically without clicking the apply-filter-button.
If have tried to use a javascript to submit the button, but this has the result, that the page is reloading again, again and again.
Does anybody have an idea to fix this problem? Is there a nice php-function or something else?