I have joined two tables like below in my ResourceModel Collection file.
protected function _initSelect() {
$this->addFilterToMap('entity_id', 'main_table.entity_id');
$this->addFilterToMap('increment_id', 'main_table.entity_id');
$this->addFilterToMap('created_at', 'main_table.entity_id');
parent::_initSelect();
$this->getSelect()->joinLeft(
('secondTable' => $this->getTable('sales_order_grid')), //2nd table name by which you want to join mail table
'main_table.entity_id = secondTable.entity_id', // common column which available in both table
'*' // '*' define that you want all column of 2nd table. if you want some particular column then you can define as ('column1','column2')
);
}
Where my mainTable is sales_order
I have called created date in ui_component like below.
<column name="created_at" class="MagentoUiComponentListingColumnsDate" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Order Date</item>
<!-- <item name="dateFormat" xsi:type="string">MMM dd, YYYY</item> //set date format as per your requirement -->
</item>
</argument>
</column>
But if I filter by the date the results are wrong. I’m searching for the year 2020 it is showing for 2016.