0

I have created a custom grid for reports in the admin without UI component. Now I want to add filters in the grid. Filters type Date-Range, Price-Range, Status.

<?php 
        protected function _prepareColumns() {
        $this->addColumn(
                'increment_id',
                [
                    'header' => __('Increment ID#'),
                    'index' => 'increment_id',
                ]
        );

        $this->addColumn(
                'order_id',
                [
                    'header' => __('Order #'),
                    'index' => 'order_id',
                ]
        );

        $this->addColumn(
            'created_at',
                [
                    'header' => __('Purchased On'),
                    'index' => 'created_at',
                ]
        );

        $this->addColumn(
            'amount_payable',
                [
                    'header' => __('Actual Amount Paid'),
                    'index' => 'amount_payable',
                ]
        );

        $this->addColumn(
            'amount_pay_later',
                [
                    'header' => __('Balance Payment'),
                    'index' => 'amount_pay_later',
                ]
        );

        $this->addColumn(
                'grand_total',
                [
                    'header' => __('Grand Total'),
                    'index' => 'grand_total',
                ]
        );
        

        $this->addColumn(
                'status',
                [
                    'header' => __('Status'),
                    'index' => 'status',
                ]
        );

        $this->addColumn(
                'method',
                [
                    'header' => __('Payment Method'),
                    'index' => 'method',
                ]
        );

                    
        $this->addColumn(
                'billing_name',
                [
                    'header' => __('Bill to Name'),
                    'index' => 'billing_name',
                ]
        );
        $this->addColumn(
                'shipping_name',
                [
                    'header' => __('Ship to Name'),
                    'index' => 'shipping_name',
                ]
        );
 


        $this->addExportType($this->getUrl('custom/*/exportCsv', ['_current' => true]), __('CSV'));
        $this->addExportType($this->getUrl('custom/*/exportExcel', ['_current' => true]), __('Excel XML'));


        $block = $this->getLayout()->getBlock('grid.bottom.links');
        if ($block) {
            $this->setChild('grid.bottom.links', $block);
        }

        return parent::_prepareColumns();
    }
?>

1 Answer 1

0

try this

$this->addColumn(
  'created_at',
    [
      'header' => __('Purchased On'),
      'index' => 'created_at',
      'type' => 'datetime'
    ]
);`

for status Grid.php

$this->addColumn(
            'website_id',
            [
                'header' => __('Website'),
                'index' => 'website_id',
                'type' => 'options',
                'options' => \companyName\ModuleName\Block\Adminhtml\Module\Grid::getStatus()
            ]
        );
....
....
static public function getStatus()
        {
            $data_array=array(); 
            $data_array[0]='Inactive';
            $data_array[1]='Active';
            return($data_array);
        }

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.