I have created a table with columns like patient_first_name, patient_last_name etc, I am able to get them in an Admin Grid Column.
<column name="patient_first_name" class="Vendor\Module\Ui\Component\Listing\Column\PatientName">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="editor" xsi:type="array">
<item name="editorType" xsi:type="string">text</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
<item name="label" xsi:type="string" translate="true">Patient Name</item>
</item>
</argument>
</column>
Inside the class, I concat first name and last name to display them in a single column in the admin grid using.
public function prepareDataSource(array $dataSource)
{
if(isset($dataSource['data']['items'])) {
foreach($dataSource['data']['items'] as &$items) {
$items['patient_first_name'] = $items['patient_first_name']." ".$items['patient_last_name'];
}
}
return $dataSource;
}
So this does its job to display the first name and last name together in the grid column, but when I use any filter to say, John Doe
it searches only the patient_first_name
column, which is correct since it is mapped that particular column but since the values would be stored as John in patient_first_name
column and Doe in patient_last_name
column, it will not return any result.
I used this solution to join both first and last names and show them together. How can I merge columns in UI grid in Magento 2 The issue comes that when you add a filter Magento tries to look for a particular column in Db, so I can't use something like patient_name and was getting the same error as here Magento 2 - custom admin grid field - error when sorting or filtering
I have tried _renderFiltersBefore but the issue with select remains.
I want to know a way how I can override the filter and write my own method which gives a select searching both first name and last name.