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.

Data Model Questions /

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

delete on gridfield change to non delete

Go to End

3 Posts   1173 Views


Community Member, 20 Posts

11 February 2014 at 9:47pm

I try to change the action in the gridfield from delete to keep the data record but change a column in the db to 3.

But in the gridfield list this record shouldn't be anymore.

I tried to change the action, but it still deletes the record.

How can I make it, that it does not delete just change the value of a column in my db but does not show the record anymore on the gridlist. It is not a relation.

Thanks for any help.


Community Member, 344 Posts

12 February 2014 at 1:59am

Edited: 12/02/2014 2:18am

First: Overload GridFieldDeleteAction->handleAction() to do your thing.

class MyGridFieldDeleteAction extends GridFieldDeleteAction{
	public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
		$item = $gridField->getList()->byID($arguments['RecordID']);
		if(!$item) {

		if($actionName == 'deleterecord') {
			$item->aColumn = 3;
		} else {
			parent::handleAction($gridField, $actionName, $arguments, $data);

Next: exclude a column with value 3 from gridfield

$list = MyObject::get()->exclude('aColumn', '3');
$gridfield = new GridField('list', 'My list', $list);

Last: remove the deletebutton and add mydeletebutton

	->addComponent(new MyGridFieldDeleteAction())


Community Member, 20 Posts

12 February 2014 at 8:53am

Hi Devlin

thanks a lot for the tipp, it helped me. acutally I had to do this:


class CustomerAdmin extends ModelAdmin {

public static $managed_models = array (
public static $url_segment = 'customerlist';
public static $menu_title = "customerlist";

public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
$gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
$gridField->getConfig()->addComponent(new GridFieldFilterHeader());
$gridField->getConfig()->addComponent(new MyGridFieldDeleteAction());

return $form;

//the record is with this function automatically removed, it's defined so from the cms
public function getList() {
$list = parent::getList();
if($this->modelClass == 'Customer') {
$list->exclude('Sync', '3');
return $list;