How would I trigger updateElements for BaseElementIndex from a plugin's JavaScript? If I wanted to update the Elements listing based on an action taken from a plugin, would it be possible to do this?

Setup:


We're on an Elements listing page.
We filter the results with a search query.
We then click an Element's name to move to its individual editing page


The Problem:

Currently in my tests with Google Chrome if I:


Filter a list by a search query (say lastName::T* on the Users listing page),
Click on one of the usernames
Hit "Back"


My search is not saved, i.e., I'm returned to a non-filtered list.

My workaround to this is to write a simple JS plugin that stores your search query - if populated - when you navigate away from the page. I then re-populate the search query when you re-enter the page but I have to tell Craft to execute it, IE to fire updateElements.

My current workaround for this is to fire a change event on the search box if the search query is stored and it's not an Ajax request. It works, it just feels kind of hacky.

So I'm wondering if there's a more native, less hacky solution.
The cleanest way to do this would be to provide your own Javascript class that overrides Craft.BaseElementIndex, which stores the latest search value in localStorage:

MyElementTypeIndex = Craft.BaseElementIndex.extend(
{
    onAfterHtmlInit: function()
    {
        // Do we have a stored search value?
        if (this.instanceState.searchVal)
        {
            this.$search.val(this.instanceState.searchVal);
        }

        this.base();
    },

    updateElements: function()
    {
        // Store the current search val in localStorage
        this.setInstanceState('searchVal', this.$search.val());

        this.base();
    }
});

// Register this as the official index class for this element type!
Craft.registerElementIndexClass('MyElementType', MyElementTypeIndex);


Save that file somewhere in your plugin’s resources/ folder (let’s say it’s craft/plugins/myplugin/resources/js/index.js), and then include it from your plugin’s init() function:

class MyPlugin extends BasePlugin
{
    // ...

    public function init()
    {
        if (craft()-&gt;request-&gt;isCpRequest())
        {
            craft()-&gt;templates-&gt;includeJsResource('myplugin/js/index.js');
        }
    }
}