I am showing custom field in my sales grid using join,i also reffered to Here

My Collection Class

public function __construct(
    EntityFactory $entityFactory,
    Logger $logger,
    FetchStrategy $fetchStrategy,
    EventManager $eventManager,
    $mainTable = 'sales_order_grid',
    $resourceModel = \Magento\Sales\Model\ResourceModel\Order::class
) {

    parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
    $this->addFilterToMap('updated_at', 'op_sales_order_table.updated_at');

// protected function _initSelect()
// {
//      parent::_initSelect();
//      $this->getSelect()->joinLeft(
//         ['op_sales_order_table' => 'sales_order'],
//         "(op_sales_order_table.entity_id = main_table.entity_id)"
//     );
//        $this->getSelect()
//               ->reset(\Zend_Db_Select::COLUMNS)
//               ->columns(['main_table.*','op_sales_order_table.updated_at as updated_at','op_sales_order_table.state as state']);

//     return $this;
// }

protected function _beforeLoad()

        $this->getSelect() ->joinInner(['op_order_table'  =>  'sales_order'],'main_table.entity_id = op_order_table.entity_id' );
        $this->addFieldToFilter('state', array('in' => $state_array));
        $data = $this->getSelect()
                                      ->columns(['main_table.*','op_order_table.updated_at as updated_att','op_order_table.state as state']);
    return $this;


        <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <label translate="true">Purchase Date</label>
     <column name="updated_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">dateRange</item>
                <item name="filter_index" xsi:type="string">op_sales_order_table.updated_at</item>
                <item name="add_field" xsi:type="boolean">false</item>
                <item name="label" xsi:type="string" translate="true">Update Datee</item>
    <column name="state">
            <label translate="true">State</label>
    <column name="billing_name">
            <label translate="true">Bill-to Name</label>

But it still not working and giving ban page error ( 403 )

can any body point out please what's wrong with this code

  • Your collection class not come in picture when you make grid using ui. here grid/collection is used. If you want to join or use this collection you have to extend collection.php to grid/collection.php – Rutvee Sojitra Jan 28 '19 at 11:54
  • Thanks for the answer but it didn't solve my problem – sheraz khan Jan 28 '19 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.