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, Ed, biapar, Willr, Ingo, swaiba

Adding custom action in view page of modeladmin

Go to End

2 Posts   2056 Views


Community Member, 151 Posts

11 April 2014 at 11:33pm

I need to extend the grid field list page with a custom button.

Please see attached image, I want to add a "Delete All" records button in my ModelAdmin extension of products, that I can control by VendorID (A product has a vendor). So that when vendors are logged in they can select delete all and upload a new set of products.

I cant use replace data on the import CSV, becuase it will replace all vendors. So i have disabled that and instead want to create a custom button that will only delete their products.


Attached Files

Community Member, 8 Posts

7 May 2014 at 12:43pm

First, you need to create a custom GridFieldComponent for 'Delete All' button - something like below

class GridFieldDeleteAllButton implements GridField_HTMLProvider, GridField_ActionProvider {
	protected $targetFragment;

	public function __construct($targetFragment = "before") {
		$this->targetFragment = $targetFragment;

	public function getHTMLFragments($gridField) {
		$button = new GridField_FormAction(
			_t('TableListField.DELETEALL', 'Delete All'),
		$button->setAttribute('data-icon', 'cross-circle');
		return array(
			$this->targetFragment => '<p class="grid-csv-button">' . $button->Field() . '</p>',

	public function getActions($gridField) {
		return array('deleteall');

	public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
		if($actionName == 'deleteall') {
			return $this->handleDeleteAll($gridField);

	public function handleDeleteAll($gridField, $request = null) {
		//Add your own DELETE logic here !
		foreach ($items as $item) {

You then can add this new component to your gridfield under your ModelAdmin extension

    public function updateEditForm(&$form) {
        $gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->owner->modelClass));
        $gridField->getConfig()->addComponent(new GridFieldDeleteAllButton('before'));