Modeladmin // getList // custom param // how to "inject" properly

I use SilverStripe 4.11

In my modeladmin I use getList() to initialize the list with a GET-param, if set.

That works as expected.

I see the items filtered by my EventID (passed via GET).
I can export the result list as CSV.
I can print the result list.

But when I use pagination or ordering in the gridfield the EventID gets lost.
And the full list without any filtering is shown.

So I guess I have to somehow inject the params to the gridfield and/or search context as well.

But so far I have no idea how to do this.

Would be great if someone could give me some tips or keywords to get me on the right track.

class MY_ADMIN extends ModelAdmin
...
    public function getList()
    {
        $list =  parent::getList();

        $arr = $this->request->getVars();
        $params = array_key_exists('q', $arr) ? $arr['q'] : null;
        if ($params && $this->modelTab === 'MY_NAMESPACE\MY_MODEL') {

            if (array_key_exists('EventID', $params))
                $list = $list->filter('EventID', $params['EventID']);
        }
        return $list;
    }
...

Instead of using a custom parameter to filter the list, I recommend using the built in filter functionality. You should be able to add your EventID field into the GridFieldFilterHeader gridfield component.

Thanks, that would be an option.

But not quite what I’m looking for.
I think I need to give a little more context.

I use SilverStripe to manage events and associated shifts.

For ease of use I created a view with calendar sheets in the admin.
What I would like to achieve is that a user can click on an event in the calendar sheet, targeting the list view of that event’s assigned work shifts.

It boils down to the question of whether it is possible, and if so, how parameters can be inserted or pre-assigned into the gridfield or search form. Preferably by just using a URL with GET parameters.

I don’t know if that would be doable with CMS 4.11 - but when 4.12 is released later this year it has some improvements to gridfield navigation (namely the state of the gridfield is stored in and rehydrated from get variables) which would allow you to do this.

That sounds very promising. Might fit perfectly.

Meanwhile I searched the api docs and tried using POST requests or manipulating the session data.
So far no success. Well, felt like guessing.

Since this feature I’m trying to build is just a nice extra, I think I’ll stop trying.

Maybe the upcoming 4.12 will bring new solutions. And if not, it’s no big deal. Still, SilverStripe is great.

Thanks for your comment.

1 Like