Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Check boxes to select records in summary table of ModelAdmin


Reply


5 Posts   1547 Views

Avatar
camfindlay

Forum Moderator, 185 Posts

7 December 2010 at 12:57pm

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 :P

Thanks in advance.

Avatar
swaiba

Forum Moderator, 1805 Posts

7 December 2010 at 9:41pm

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...

Avatar
James Bolitho

Community Member, 33 Posts

7 March 2012 at 4:47am

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

Avatar
Bereusei

Community Member, 94 Posts

17 March 2012 at 5:47am

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?

Avatar
danzzz

Community Member, 175 Posts

20 March 2012 at 8:08pm

hi

if you need to modify modeladmin you may want to read this article:
http://www.leftandmain.com/uncategorized/2011/02/25/taming-the-beast-remodeling-modeladmin/