jquerycustomizationsilverstripemodeladmin

Show filter-form in Silverstripe's ModelAdmin by default


I added a ModelAdmin to my silverstripe site. This includes a filter form, which slides down when the user clicks the loupe icon in the frontend. How can I make the form visible by default (without user interaction)?

Up to now I tried to call the showHide() of LeftAndMain.js with entwine, but as Silvertripe relies heavily on Ajax this only shows the form on the initial page load.

(function($) {
    $('#filters-button').entwine({
        onadd: function(){
            this._super();
            this.entwine('ss').showHide();
        }
    });
})(jQuery);

Solution

  • You can show the filters by default by using CSS (replace .MyAdmin with the classname of your ModelAdmin):

    /* file: mysite/css/admin-extensions.css */
    .MyAdmin .cms-content-filters {
        display: block;
    }
    

    Then add the css file to your requirements:

    LeftAndMain:
      extra_requirements_css:
        - 'mysite/cms/css/admin-extensions.css'
    

    Run ?flush to make SilverStripe aware of the changes.