分类
Magento 数据库

magento2 ui components listing how to add custom param

# maijindou_enquire_enquireitem_listing.xml
<dataSource name="maijindou_enquire_enquireitem_listing_data_source" component="Magento_Ui/js/grid/provider">
        <settings>
            <updateUrl path="mui/index/render"/>
            <filterUrlParams>
                <param name="enquire_id">*</param>
            </filterUrlParams>
        </settings>
    </dataSource>

# \Maijindou\Enquire\Model\ResourceModel\EnquireItem\Grid\Collection
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
{

    public function __construct(
        EntityFactory $entityFactory,
        Logger $logger,
        FetchStrategy $fetchStrategy,
        EventManager $eventManager,
        $mainTable='maijindou_enquire_enquireitem',
        $resourceModel = '\Maijindou\Enquire\Model\ResourceModel\EnquireItem',
        $identifierName = 'enquireitem_id',
        $connectionName = null
    )
    {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel, $identifierName, $connectionName);
    }

    protected function _initSelect()
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $context = $objectManager->get('\Magento\Framework\View\Element\UiComponent\ContextInterface');
        $enquire_id = $context->getRequestParam("enquire_id");
        $select = parent::_initSelect();
        if ($enquire_id) {
            $select->addFieldToFilter("enquire_id", $enquire_id);
        }
        return $select;
    }
}