I have a module, in this there is a field which contains the id from customer table.
In my admin grid listing I show the name of the customer, not the id. When i short this grid by the field, the short order which is considerer is by the id, not the name.
There is a way of short this grid by name of the customer?
Field in the listing admin grid
<column name="specifier" class="vendor\module\Ui\Component\Listing\Column\Specifier">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="editor" xsi:type="array">
<item name="editorType" xsi:type="string">text</item>
</item>
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">desc</item>
<item name="label" xsi:type="string" translate="true">Especificador</item>
</item>
</argument>
</column>
Function that changes the value from id to name. vendor\module\Ui\Component\Listing\Column\Specifier
public function prepareDataSource(array $dataSource)
{
$i = 0;
while ($i < count($dataSource['data']['items'])) {
if (isset($dataSource['data']['items'][$i]['specifier'])) {
$customer = $this->_customerCollectionFactory->getItemById($dataSource['data']['items'][$i]['specifier']);
if ($customer) {
$dataSource['data']['items'][$i]['specifier'] = $customer->getData('firstname') . ' ' . $customer->getData('lastname');
} else {
$dataSource['data']['items'][$i]['specifier'] = 'Especificador não encontrado ';
}
}
$i = $i + 1;
}
return $dataSource;
}
Here a exemplo, "BB" came first of "AAAA" because the id came first.