0

i want to add search field here where records shows up

enter image description here

grid.php

<?php
namespace Vendor\Module\Block\Adminhtml\Sales\Mycustomreport;
class Grid extends \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid

{
    protected $_columnGroupBy = 'period';
    protected function _construct()
    {
        parent::_construct();
        $this->setCountTotals(true);
    }
    public function getResourceCollectionName()
    {
        return \Vendor\Module\Model\ResourceModel\Report\MyCustomReport\Collection::class;
    }
    protected function _prepareColumns()
    {
        $this->addColumn(
            'period',
            [
                'header' => __('Interval'),
                'index' => 'period',
                'sortable' => false,
                'period_type' => $this->getPeriodType(),
                'renderer' => \Magento\Reports\Block\Adminhtml\Sales\Grid\Column\Renderer\Date::class,
                'totals_label' => __('Total'),
                'html_decorators' => ['nobr'],
                'header_css_class' => 'col-period',
                'column_css_class' => 'col-period'
            ]
        );

        $this->addColumn(
            'product_sku',
            [
                'header' => __('SKU'),
                'index' => 'product_sku',
                'type' => 'string',
                'sortable' => false,
                'header_css_class' => 'col-product',
                'column_css_class' => 'col-product'
            ]
        );

        $this->addColumn(
            'product_name',
            [
                'header' => __('Product'),
                'index' => 'product_name',
                'type' => 'string',
                'sortable' => false,
                'header_css_class' => 'col-product',
                'column_css_class' => 'col-product'
            ]
        );

        if ($this->getFilterData()->getStoreIds()) {
            $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds()));
        }

        $this->addColumn(
            'qty_ordered',
            [
                'header' => __('Order Quantity'),
                'index' => 'qty_ordered',
                'type' => 'number',
                'total' => 'sum',
                'sortable' => false,
                'header_css_class' => 'col-qty',
                'column_css_class' => 'col-qty'
            ]
        );


        $this->addExportType('*/*/exportMyCustomReportCsv', __('CSV'));
        $this->addExportType('*/*/exportMyCustomReportExcel', __('Excel XML'));

        return parent::_prepareColumns();
    }
}

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Reports\Model\ResourceModel\Refresh\Collection">
        <plugin name="vendor_module_report_mycustomreport" type="Vendor\Module\Plugin\Magento\Reports\Model\ResourceModel\Refresh\Collection" sortOrder="1" />
    </type>

    <type name="Magento\Reports\Controller\Adminhtml\Report\Statistics">
        <arguments>
            <argument name="reportTypes" xsi:type="array">
                <item name="mycustomreport" xsi:type="string">Vendor\Module\Model\ResourceModel\Report\MyCustomReport</item>
            </argument>
        </arguments>
    </type>
</config>

note:- am not using ui component

1 Answer 1

1

Update your grid.php function _construct() with below code, It will add a filter on column top.

protected function _construct()
    {
        parent::_construct();
        $this->setCountTotals(true);
        $this->setFilterVisibility(true);
    }

Hope this help!

2
  • i cant believe this did the trick thanks a lot
    – Pramod
    Feb 27, 2020 at 13:02
  • @Pramod Welcome :) Keep Kudos..! Feb 27, 2020 at 13:09

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.