1

I want to show data according to the id that is shown in my URL..... my URL is

http://dev.magento.com/admin/customer/index/edit/id/1/key/06ae49324c0bb7e328bc5bd4bb75954fcc787d538a59cb97ce4e1809a1a17ff3/#

my code is

<item name="filter_url_params" xsi:type="array">
                    <item name="customer_id" xsi:type="string">id</item>
                </item>

When I call this it treats "id" as a string and matches "id" as a string in my table column "customer_id" rather than its value.

  • when I call "*" instead of "id" it gives me a full database record
  • when I call a specific value like "2" it returns me records of customer_id "2"
  • when I call "id" it returns me values of customer_id "0"

kindly someone please help!!!

4
  • hey how are you! I'm actually looking for something like this, were you able to solve this? thanks in advance May 16, 2019 at 18:41
  • hi, i am fine . no i can't solve it in this way i solved it by another way
    – Asad Ullah
    May 17, 2019 at 9:17
  • Can you please help me? which method did you use? is there any link you can give me so I can guide? Thanks! May 17, 2019 at 21:16
  • i don't remember the link and also i checked my extension i that problem is still pending for me sorry can't help in this
    – Asad Ullah
    May 20, 2019 at 5:56

2 Answers 2

1

You need add parameter name "customer_id" to your url. And change <item name="customer_id" xsi:type="string">id</item> to <item name="customer_id" xsi:type="string">*</item>

1

change di.xml and add replace <virtualType> of datasource with <type>

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="blackout_data_source" xsi:type="string">
                vendor\module\Model\ResourceModel\BlackoutLimit\Grid\Collection
            </item>
        </argument>
    </arguments>
</type>

Add <Type> of grid/collection in same di.xml as below add variables name "maintable" "eventPrefix" "eventObject"

<type name="vendor\module\Model\ResourceModel\BlackoutLimit\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">tm_blackout_days_limit</argument>
            <argument name="eventPrefix" xsi:type="string">tm_blackoutlimit_blackout_collection</argument>
            <argument name="eventObject" xsi:type="string">blackout_collection</argument>
            <argument name="resourceModel" xsi:type="string">vendor\module\Model\ResourceModel\BlackoutLimit</argument>
        </arguments>
    </type>

Create Grid collection file as below

vendor\module\Model\ResourceModel\BlackoutLimit\Grid\Collection.php


<?php

namespace vendor\module\Model\ResourceModel\BlackoutLimit\Grid;

class Collection extends \vendor\module\Model\ResourceModel\BlackoutLimit\Collection implements \Magento\Framework\Api\Search\SearchResultInterface {

protected $_idFieldName = 'day_limit_id';
protected $_eventPrefix = 'tm_blackoutlimit_blackout_collection';
protected $_eventObject = 'blackout_collection';

/**
 *
 * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory            
 * @param \Psr\Log\LoggerInterface $logger            
 * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy            
 * @param \Magento\Framework\Event\ManagerInterface $eventManager            
 * @param \Magento\Store\Model\StoreManagerInterface $storeManager            
 * @param mixed|null $mainTable            
 * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix            
 * @param mixed $eventObject            
 * @param mixed $resourceModel            
 * @param string $model            
 * @param null $connection            
 * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
 *            @SuppressWarnings(PHPMD.ExcessiveParameterList)
 *            
 */
public function __construct(\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, 
    \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, 
    \Magento\Framework\Event\ManagerInterface $eventManager, 
    \Magento\Store\Model\StoreManagerInterface $storeManager, $mainTable, $eventPrefix, $eventObject, $resourceModel, 
    $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document', $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null)
{ 
    parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
    $this->logger = $logger;
    $this->_eventPrefix = $eventPrefix;
    $this->_eventObject = $eventObject;
    $this->_init($model, $resourceModel);
    $this->setMainTable($mainTable);
    $this->storeManager = $storeManager;
}

/**
 *
 * @return \Magento\Framework\Api\Search\AggregationInterface
 */
public function getAggregations()
{
    return $this->aggregations;
}

/**
 *
 * @param \Magento\Framework\Api\Search\AggregationInterface $aggregations            
 * @return void
 */
public function setAggregations($aggregations)
{
    $this->aggregations = $aggregations;
}

/**
 *
 * @return \Magento\Framework\Api\Search\SearchCriteriaInterface|null
 */
public function getSearchCriteria()
{
    return $this->searchCriteria;
}

/**
 *
 * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria            
 * @return $this @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
    $this->searchCriteria = $searchCriteria;
    return $this;
}

/**
 * Get total count.
 *
 * @return int
 */
public function getTotalCount()
{
    return $this->getSize();
}

/**
 * Set total count.
 *
 * @param int $totalCount            
 * @return $this @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setTotalCount($totalCount)
{
    return $this;
}

/**
 * Set items list.
 *
 * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items            
 * @return $this @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setItems(array $items = null)
{
    return $this;
}

/**
 * This is the function that will add the filter
 */
    protected function _beforeLoad()
    {   
parent::_beforeLoad();
        $mydate=getdate(date("U"));
        $this->addFieldTOFilter( 'day_code',array( 'like' => '%'."$mydate[year]".'%' ) );            
        return $this;
    }    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.