1

In Magento 2.2.5, I have a custom agrid. It has edit option and url parameters.

I need to create another grid in the edit page based on the url parameter. ie., I need to filter the custom grid based on the url parameter.

Note: Am not using ui component to create grid.

Code: https://pastebin.com/z9aww705

Screenshot

asked Oct 3, 2018 at 5:37
1
  • Could you please add your ui component file ? Commented Oct 3, 2018 at 6:30

2 Answers 2

2

Please find below line in your ui component file.

<item name="update_url" xsi:type="url" path="mui/index/render"/>

After that add below code after that line.

<item name="filter_url_params" xsi:type="array"> 
 <item name="id" xsi:type="boolean">1</item>
 </item>

You can get filter data in your grid.

Still you have any query let me know.

answered Oct 3, 2018 at 6:38
8
  • Thanks for your response. It is not in ui component. Commented Oct 3, 2018 at 7:44
  • where you need it ? Commented Oct 3, 2018 at 7:45
  • I mean I am not using Ui component to create this grid. I am using normal blocks. Commented Oct 3, 2018 at 7:46
  • could you please post your code? Commented Oct 3, 2018 at 7:47
  • please find my code here pastebin.com/z9aww705 Commented Oct 3, 2018 at 7:53
0

Reference: Marius answer

In the layout xml file, change the Core Grid block to Custom Grid Block like below:

<block class="Magento\Backend\Block\Widget\Grid" name="apptha_merchant_post_grid.grid" as="grid">

Change this to:

<block class="Apptha\Customergroup\Block\Adminhtml\Response" name="apptha_merchant_post_grid.grid" as="grid">

Code of the Block File is:

<?php
namespace Apptha\Customergroup\Block\Adminhtml;
class Response extends \Magento\Backend\Block\Widget\Grid
{ 
public function _construct()
{
parent::_construct();
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $referenceId = $objectManager->create('Apptha\Customergroup\Model\Deal')
->load($this->getRequest()->getParam('id'))->getData("reference_id");
//We'll get the Grid collection here by using this: $this->getCollection()
//We can filter it like addFieldToFilter method
//Here I am filtering grid collection using reference id
$this->getCollection()->addFieldToFilter('reference_id', array('eq' => $referenceId));
}
}
answered Oct 3, 2018 at 11:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.