How to Filter a Custom column with custom data in Products grid?












0














I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:




[2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name: parentid_col {"exception":"[object] (MagentoFrameworkExceptionLocalizedException(code: 0): Invalid attribute name: parentid_col at /html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}




Here's my code




app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component/product_listing.xml




<?xml version="1.0" encoding="utf-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns">
<column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Parent id</item>
<item name="filter" xsi:type="string">text</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="align" xsi:type="string">left</item>
<item name="dataType" xsi:type="string">text</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
</columns>
</listing>



app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php




<?php


namespace CustomColumnAddproductcolumnUiComponentListingColumn;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoUiComponentListingColumnsColumn;

class ParentProductId extends Column
{
protected $configurable;
protected $bundle;
protected $_productFactory;

public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
MagentoCatalogModelProductFactory $productFactory,

MagentoConfigurableProductModelProductTypeConfigurable $configurable,
MagentoBundleModelProductType $bundle,

array $components = ,
array $data =
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->_configurable = $configurable;
$this->_bundle = $bundle;
$this->_productFactory = $productFactory;

}

public function prepareDataSource(array $dataSource)
{


if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$items) {
if($items['type_id'] == 'simple'){

$productId = $items['entity_id'];
$parentProducts = '';

$getParent = $this->_configurable->getParentIdsByChild($productId);
$parentData = $this->_productFactory->create()->load($getParent);
$getParentSku = $parentData->getSku();

if(isset($getParentSku)){
$parentProducts .= $getParentSku;
}

$getParent = $this->_bundle->getParentIdsByChild($productId);
if(isset($getParent)){

foreach ($getParent as $p) {
$parentData = $this->_productFactory->create()->load($p);
$getParentSku = $parentData->getSku();
$parentProducts .= $getParentSku.',';
}
$items['parentid_col'] = $parentProducts;
}

}
}
}
return $dataSource;
}


}









share|improve this question









New contributor




Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0














    I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:




    [2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name: parentid_col {"exception":"[object] (MagentoFrameworkExceptionLocalizedException(code: 0): Invalid attribute name: parentid_col at /html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}




    Here's my code




    app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component/product_listing.xml




    <?xml version="1.0" encoding="utf-8"?>

    <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="product_columns">
    <column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="label" xsi:type="string" translate="true">Parent id</item>
    <item name="filter" xsi:type="string">text</item>
    <item name="visible" xsi:type="boolean">true</item>
    <item name="sortOrder" xsi:type="number">50</item>
    <item name="align" xsi:type="string">left</item>
    <item name="dataType" xsi:type="string">text</item>
    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
    </item>
    </argument>
    </column>
    </columns>
    </listing>



    app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php




    <?php


    namespace CustomColumnAddproductcolumnUiComponentListingColumn;
    use MagentoFrameworkViewElementUiComponentFactory;
    use MagentoFrameworkViewElementUiComponentContextInterface;
    use MagentoUiComponentListingColumnsColumn;

    class ParentProductId extends Column
    {
    protected $configurable;
    protected $bundle;
    protected $_productFactory;

    public function __construct(
    ContextInterface $context,
    UiComponentFactory $uiComponentFactory,
    MagentoCatalogModelProductFactory $productFactory,

    MagentoConfigurableProductModelProductTypeConfigurable $configurable,
    MagentoBundleModelProductType $bundle,

    array $components = ,
    array $data =
    ) {
    parent::__construct($context, $uiComponentFactory, $components, $data);
    $this->_configurable = $configurable;
    $this->_bundle = $bundle;
    $this->_productFactory = $productFactory;

    }

    public function prepareDataSource(array $dataSource)
    {


    if (isset($dataSource['data']['items'])) {
    foreach ($dataSource['data']['items'] as &$items) {
    if($items['type_id'] == 'simple'){

    $productId = $items['entity_id'];
    $parentProducts = '';

    $getParent = $this->_configurable->getParentIdsByChild($productId);
    $parentData = $this->_productFactory->create()->load($getParent);
    $getParentSku = $parentData->getSku();

    if(isset($getParentSku)){
    $parentProducts .= $getParentSku;
    }

    $getParent = $this->_bundle->getParentIdsByChild($productId);
    if(isset($getParent)){

    foreach ($getParent as $p) {
    $parentData = $this->_productFactory->create()->load($p);
    $getParentSku = $parentData->getSku();
    $parentProducts .= $getParentSku.',';
    }
    $items['parentid_col'] = $parentProducts;
    }

    }
    }
    }
    return $dataSource;
    }


    }









    share|improve this question









    New contributor




    Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0







      I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:




      [2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name: parentid_col {"exception":"[object] (MagentoFrameworkExceptionLocalizedException(code: 0): Invalid attribute name: parentid_col at /html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}




      Here's my code




      app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component/product_listing.xml




      <?xml version="1.0" encoding="utf-8"?>

      <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
      <columns name="product_columns">
      <column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">Parent id</item>
      <item name="filter" xsi:type="string">text</item>
      <item name="visible" xsi:type="boolean">true</item>
      <item name="sortOrder" xsi:type="number">50</item>
      <item name="align" xsi:type="string">left</item>
      <item name="dataType" xsi:type="string">text</item>
      <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
      </item>
      </argument>
      </column>
      </columns>
      </listing>



      app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php




      <?php


      namespace CustomColumnAddproductcolumnUiComponentListingColumn;
      use MagentoFrameworkViewElementUiComponentFactory;
      use MagentoFrameworkViewElementUiComponentContextInterface;
      use MagentoUiComponentListingColumnsColumn;

      class ParentProductId extends Column
      {
      protected $configurable;
      protected $bundle;
      protected $_productFactory;

      public function __construct(
      ContextInterface $context,
      UiComponentFactory $uiComponentFactory,
      MagentoCatalogModelProductFactory $productFactory,

      MagentoConfigurableProductModelProductTypeConfigurable $configurable,
      MagentoBundleModelProductType $bundle,

      array $components = ,
      array $data =
      ) {
      parent::__construct($context, $uiComponentFactory, $components, $data);
      $this->_configurable = $configurable;
      $this->_bundle = $bundle;
      $this->_productFactory = $productFactory;

      }

      public function prepareDataSource(array $dataSource)
      {


      if (isset($dataSource['data']['items'])) {
      foreach ($dataSource['data']['items'] as &$items) {
      if($items['type_id'] == 'simple'){

      $productId = $items['entity_id'];
      $parentProducts = '';

      $getParent = $this->_configurable->getParentIdsByChild($productId);
      $parentData = $this->_productFactory->create()->load($getParent);
      $getParentSku = $parentData->getSku();

      if(isset($getParentSku)){
      $parentProducts .= $getParentSku;
      }

      $getParent = $this->_bundle->getParentIdsByChild($productId);
      if(isset($getParent)){

      foreach ($getParent as $p) {
      $parentData = $this->_productFactory->create()->load($p);
      $getParentSku = $parentData->getSku();
      $parentProducts .= $getParentSku.',';
      }
      $items['parentid_col'] = $parentProducts;
      }

      }
      }
      }
      return $dataSource;
      }


      }









      share|improve this question









      New contributor




      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:




      [2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name: parentid_col {"exception":"[object] (MagentoFrameworkExceptionLocalizedException(code: 0): Invalid attribute name: parentid_col at /html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}




      Here's my code




      app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component/product_listing.xml




      <?xml version="1.0" encoding="utf-8"?>

      <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
      <columns name="product_columns">
      <column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">Parent id</item>
      <item name="filter" xsi:type="string">text</item>
      <item name="visible" xsi:type="boolean">true</item>
      <item name="sortOrder" xsi:type="number">50</item>
      <item name="align" xsi:type="string">left</item>
      <item name="dataType" xsi:type="string">text</item>
      <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
      </item>
      </argument>
      </column>
      </columns>
      </listing>



      app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php




      <?php


      namespace CustomColumnAddproductcolumnUiComponentListingColumn;
      use MagentoFrameworkViewElementUiComponentFactory;
      use MagentoFrameworkViewElementUiComponentContextInterface;
      use MagentoUiComponentListingColumnsColumn;

      class ParentProductId extends Column
      {
      protected $configurable;
      protected $bundle;
      protected $_productFactory;

      public function __construct(
      ContextInterface $context,
      UiComponentFactory $uiComponentFactory,
      MagentoCatalogModelProductFactory $productFactory,

      MagentoConfigurableProductModelProductTypeConfigurable $configurable,
      MagentoBundleModelProductType $bundle,

      array $components = ,
      array $data =
      ) {
      parent::__construct($context, $uiComponentFactory, $components, $data);
      $this->_configurable = $configurable;
      $this->_bundle = $bundle;
      $this->_productFactory = $productFactory;

      }

      public function prepareDataSource(array $dataSource)
      {


      if (isset($dataSource['data']['items'])) {
      foreach ($dataSource['data']['items'] as &$items) {
      if($items['type_id'] == 'simple'){

      $productId = $items['entity_id'];
      $parentProducts = '';

      $getParent = $this->_configurable->getParentIdsByChild($productId);
      $parentData = $this->_productFactory->create()->load($getParent);
      $getParentSku = $parentData->getSku();

      if(isset($getParentSku)){
      $parentProducts .= $getParentSku;
      }

      $getParent = $this->_bundle->getParentIdsByChild($productId);
      if(isset($getParent)){

      foreach ($getParent as $p) {
      $parentData = $this->_productFactory->create()->load($p);
      $getParentSku = $parentData->getSku();
      $parentProducts .= $getParentSku.',';
      }
      $items['parentid_col'] = $parentProducts;
      }

      }
      }
      }
      return $dataSource;
      }


      }






      magento2 filter magento2.2.4 product-grid custom-column-grid






      share|improve this question









      New contributor




      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 23 hours ago









      Manashvi Birla

      6,09441840




      6,09441840






      New contributor




      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      Tajveez Rehman

      34




      34




      New contributor




      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Tajveez Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256713%2fhow-to-filter-a-custom-column-with-custom-data-in-products-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.













          Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.












          Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256713%2fhow-to-filter-a-custom-column-with-custom-data-in-products-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          An IMO inspired problem

          Management

          Investment