Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » ModelAdmin show all results on first load

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 6617 Views
  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    ModelAdmin show all results on first load Link to this post

    Was wondering if it is possible to show the results of a search (like show everything) when you first click on a ModelAdmin tab instead of having to do a search first?

  • UncleCheese
    Avatar
    4085 Posts

    Re: ModelAdmin show all results on first load Link to this post

    Join the club.

    It's a huge criticism of ModelAdmin, and personally I can't for the life of me figure out why they built it that way. Somewhere around the forums you'll find a Javascript hack that I use to force a list view by default. If you can't find it let me know and I'll dig it up.

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: ModelAdmin show all results on first load Link to this post

    Hey UncleCheese thanks for the response

    I found the following but still doesn't really provide an answer :

    http://www.silverstripe.org/general-questions/show/255859#post255859

    http://www.silverstripe.org/customising-the-cms/show/262049#post262049

    Ingo Mentions

    It uses DataObject::$default_sort. You can overload ModelAdmin->getResultsTable() and ModelAdmin->getCustomQuery() for any custom sorting.

    And

    You can overload the right template by adding a new Layout template called RegionAdmin_right.ss (see ModelAdmin_right.ss for clues on the necessary markup)

    But I guess with out subclassing and overloading most of model admin this would be a real pain.

    So if you could dig up that JS hack would be greatly appreciated!

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: ModelAdmin show all results on first load Link to this post

    Any luck finding the JS hack UncleCheese?

    Edit: Anyone?????

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: ModelAdmin show all results on first load Link to this post

    Yes hacky but at least it loads some results when you first go to your ModelAdmin tab anyone has a better way please let me know

    ProductAdmin.php

    class ProductAdmin extends ModelAdmin {

    ...

    function init()
    {
       parent::init();
       
       Requirements::javascript('site/javascript/ProductAdmin.js');
    }
    }

    ProductAdmin.js

    (function($) {
    $(document).ready(function() {
       $('#Form_SearchForm_Product').submit();
    })
    })(jQuery);

    Note: the above form id passed to the jQuery selector will changed based on what you called your extended ModelAdmin class

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: ModelAdmin show all results on first load Link to this post

    And to trigger an empty search for each tab when clicked add this to CG's function for each managed model:

       $('a[href$=#Form_Product]').click(function() {
          $('#Form_SearchForm_Product').submit();
       });

    Again, replacing Product with your models class name.

    The combobox version would just need some tweaking.

  • liece
    Avatar
    Community Member
    9 Posts

    Re: ModelAdmin show all results on first load Link to this post

    Thanks!

    That worked perfectly.

  • Shadlan
    Avatar
    Community Member
    2 Posts

    Re: ModelAdmin show all results on first load Link to this post

    For those of you that are using a Select instead of tabs, you can also try this JQuery solution:

    $('#ModelClassSelector select').change(function () {
    $('#SearchForm_holder div.tab:visible form[id^=Form_SearchForm]').submit();
    });

    6617 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.