GridField custom action

Silverstripe Version: 4.5.2


I have added a custom action button to a GridField row, as per the documentation:

This appears to be working fine, but I have 2 questions:

  1. how do I style the button? I can eg. use DBField within a GridField row to create an HTML styled button (green icon on left). Where and how do I apply this styling to the grey custom action button?
  2. how/where do I apply conditional logic to display the button? Eg. I’d like to only display the button over 3 days around the current date and hide it the rest of the time.


Ok, have figured this out…

Both of these issues can be configured via the getColumnContent function. eg.

public function getColumnContent($gridField, $record, $columnName) 
    if (!$record->canEdit()) {

    // only display if trip starting 2 days before/after today
    $daysDiff = $record->dbObject('DateTimeStart')->TimeDiffIn('days');
    if ($daysDiff > 2) {

    $field = GridField_FormAction::create(
        ['RecordID' => $record->ID]
        // format custom action button
        ->addExtraClass('btn btn--no-text btn--icon-xl font-icon-up-circled')
        ->setAttribute('style', 'transform:rotate(90deg); color:white; background:green; padding:.5em; border-radius: 5px;')
        ->setDescription('Sign in ' . $record->Title);

    return $field->Field();
1 Like