Question

I've got an Event content type that has coupled events. The content type does not have a title. I've defined a searchable_fields private static:

private static $searchable_fields = array(
    'ProjectNumber',
    'EventDate'             => 'PartialMatch',
    'TicketCode'            => 'PartialMatch',
    "Package.Title"         => 'PartialMatch',
);

Searching in the field (see attachment) is working, but I only see the ID, whcih is, to say the least, less than optimal :-). Does anyone know how to override the system in such a way that it shows the TicketCode or EventDate?

Dropdown example

Was it helpful?

Solution

By default, the GridFieldAddExistingAutocompleter displays the $Title of the result. If you don't have Title or Name field, this defaults to #$ID, as you're seeing.

You can either add a getTitle method to your class that returns what you want, or change what gets returned by the component.

You'd do this using something like:

$config->getComponentByType('GridFieldAddExistingAutocompleter')->setResultsFormat('$TicketCode - $EventDate.Nice');

OTHER TIPS

Define the fields you'd like to display in the GridField using:

private static $summary_fields = array(
    'TicketCode',
    'EventDate'
);

Documentation here: http://doc.silverstripe.org/framework/en/reference/dataobject#summary-fields

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top