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 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>

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. Here a exemplo, "BB" came first of "AAAA" because the id came first.

1 Answer 1


You must have to join your customer table with current data source in your model. Then after you can search by name of customer.

Because your grid collection is not having customer name. In your grid collection table only customer id available. So you must have to join customer table with your grid collection then and then you can search grid by customer name.

For join two table collections refer below link

Magento2 Join

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.