Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Check boxes to select records in summary table of ModelAdmin

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1344 Views
  • camfindlay
    Avatar
    Forum Moderator
    74 Posts

    Check boxes to select records in summary table of ModelAdmin Link to this post

    Hi all,
    I have been going nuts trying to work this out and have scoured the forums looking for any code or other people that have come up against this same problem.

    Basically I have a client who I have built a sales logging system for using SS, there is a Sale dataobject which holds a bunch of information about the sale including a "Status" (Enum) which allows the following statuses: Pending, Cancelled, Active, Invoiced.

    On the front end I have everything running so his sales reps can log the sales they make, the reps themselves change the Sale dataobject status to "active".
    My client then would go and in the CMS using the ModelAdmin interface I setup for him, find the Active Sales, and mark them as "Invoiced" when he performs his accounting processes.

    This was happening on a record by record basis, i.e. he opened the record in ModelAdmin, changed the dropbox, saved and clicked back.

    Problem being he now wants to have a checkbox in the ModelAdmin summary table that he can just select more than one record at a time and select a button to mark ALL those records as "Invoiced" at once.

    I could pretty easily sort this out on the front end for him but he has explicitly requested that this feature be included into the CMS (ModelAdmin).

    Has anyone any idea about how to achieve this or at least point me in the right direction about how to add extra columns to the ModelAdmin summary table and be able to submit these to a method either serverside or ajax which I can then perform some action against only the selected rows?

    Doing my head in

    Thanks in advance.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Check boxes to select records in summary table of ModelAdmin Link to this post

    How about....

    1)adding a cast to the summary fields (http://doc.silverstripe.org/datamodel?s[]=cast#casting) to display a check box (or an image of a check box) that has knowledge of the row's id
    2)add an onclick to this that performs an ajax request to change the state of the row (using the ID)
    3)upon success this then updates the checkbox accordingly (with unchecking on failure if using a checkbox or changing the image if using images for your checkbox)

    hope this helps...

  • James Bolitho
    Avatar
    Community Member
    33 Posts

    Re: Check boxes to select records in summary table of ModelAdmin Link to this post

    Hi,

    I know this is an old post but I would like to do something similar. So far I have managed to get checkboxes to appear for each record by adding the following code to my Model Admin code:

    class ProductAdmin extends DataObjectAsPageAdmin {

    public static $managed_models = array(
    'Product'
    );

    static $url_segment = 'products';
    static $menu_title = 'Products';
    public static $record_controller_class = "ProductAdmin_RecordController";
    public static $collection_controller_class = "ProductAdmin_CollectionController";
    }
    class ProductAdmin_RecordController extends ModelAdmin_RecordController {

    }
    class ProductAdmin_CollectionController extends ModelAdmin_CollectionController {
       function getResultsTable($searchCriteria) {
          $tableField = parent::getResultsTable($searchCriteria);
          $tableField->MarkableTitle = "Select";
          $tableField->Markable = true;
          return $tableField;   
       }
    }

    Now I would like to add a delete button at the bottom of the table list field in order to allow deletion of all the selected items. This is where I have got stuck so would be grateful if anyone has any code they would like to share or point me in the right direction.

    Cheers,

    Jim

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Check boxes to select records in summary table of ModelAdmin Link to this post

    Hi,

    I have the same issue. I think we must do something like this http://www.ssbits.com/tutorials/2009/adding-a-cms-action-the-slightly-hacky-way/

    But I canĀ“t figure out, how to create a button to the summary field. With the function getCMSActions() we can create a button within the DataObject class, but the button must be create within the ModelAdmin, I think.

    Did you already find a solution, Jim?

  • danzzz
    Avatar
    Community Member
    175 Posts
    1344 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.