문제

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

도움이 되었습니까?

해결책

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');

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top