Adding search for archived data objects

Silverstripe Version: 4.9

Question: Hey,

I’m trying to add a search bar to archived records for a given data object class. I already have an extension working that contains a updateEditForm action that is called when the list of archived objects is opened, but I have no idea how to add a search function to that list.

class ArchiveAdminExtension extends Extension
    {
        public function updateEditForm(&$form)
        {
            if ($this->owner->modelClass === MyClass::class) {
                $field = new SilverStripe\Forms\GridField\GridFieldFilterHeader();

               // how to add this filter header to the page?

                if ($GridField = $form->Fields()->dataFieldByName('Others')) {
                    if ($Header = $GridField->getConfig()->getComponentByType(GridFieldDataColumns::class)) {

                    }

                }
            }
            return $form->Fields();
        }
}

You just need to add the filter header to the GridField’s config.

$gridField->getConfig()->addComponent(GridFieldFilterHeader::create());

Whether that will work correctly out-of-the-box with your archived list, I’m not sure. It theoretically should, though.

Thanks @GuySartorelli, I’ve tried:

public function updateEditForm(&$form)
{
    if ($this->owner->modelClass === MyClass::class) {
        if ($GridField = $form->Fields()->dataFieldByName('Others')) {
            $GridField->getConfig()->addComponent(new GridFieldFilterHeader());
        }
    }
    return $form->Fields();
}

But not filter is displayed. Can you point me in the right direction?

I also could not use GridFieldFilterHeader::create() because the function is not existing.

Hi Ben,

I noticed this popped up on the public slack as well. Did you end up getting a working solution in the end? If so, it could be a good idea to drop the solution in here for anyone else who comes across this in the future.