Custom column in Product Grid not being filtered?












2














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




/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component




<?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.




















  • How did you add this attribute?
    – Anshu Mishra
    yesterday










  • @AnshuMishra i have created module to add this attribute in product listing grid
    – Tajveez Rehman
    23 hours ago












  • Please share the code that you have written to add the custom attribute.
    – Anshu Mishra
    23 hours ago










  • @AnshuMishraI I've already did that above in question's description
    – Tajveez Rehman
    22 hours ago
















2














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




/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component




<?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.




















  • How did you add this attribute?
    – Anshu Mishra
    yesterday










  • @AnshuMishra i have created module to add this attribute in product listing grid
    – Tajveez Rehman
    23 hours ago












  • Please share the code that you have written to add the custom attribute.
    – Anshu Mishra
    23 hours ago










  • @AnshuMishraI I've already did that above in question's description
    – Tajveez Rehman
    22 hours ago














2












2








2







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




/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component




<?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




/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component




<?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






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 22 hours ago







Tajveez Rehman













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 RehmanTajveez Rehman

135




135




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.












  • How did you add this attribute?
    – Anshu Mishra
    yesterday










  • @AnshuMishra i have created module to add this attribute in product listing grid
    – Tajveez Rehman
    23 hours ago












  • Please share the code that you have written to add the custom attribute.
    – Anshu Mishra
    23 hours ago










  • @AnshuMishraI I've already did that above in question's description
    – Tajveez Rehman
    22 hours ago


















  • How did you add this attribute?
    – Anshu Mishra
    yesterday










  • @AnshuMishra i have created module to add this attribute in product listing grid
    – Tajveez Rehman
    23 hours ago












  • Please share the code that you have written to add the custom attribute.
    – Anshu Mishra
    23 hours ago










  • @AnshuMishraI I've already did that above in question's description
    – Tajveez Rehman
    22 hours ago
















How did you add this attribute?
– Anshu Mishra
yesterday




How did you add this attribute?
– Anshu Mishra
yesterday












@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago






@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago














Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago




Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago












@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago




@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago










1 Answer
1






active

oldest

votes


















0














You need to add this below code in your ParentProductId.php file :



protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}





share|improve this answer





















  • Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
    – Tajveez Rehman
    yesterday










  • i have added this but its still giving the same error
    – Tajveez Rehman
    23 hours ago











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%2f256904%2fcustom-column-in-product-grid-not-being-filtered%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You need to add this below code in your ParentProductId.php file :



protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}





share|improve this answer





















  • Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
    – Tajveez Rehman
    yesterday










  • i have added this but its still giving the same error
    – Tajveez Rehman
    23 hours ago
















0














You need to add this below code in your ParentProductId.php file :



protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}





share|improve this answer





















  • Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
    – Tajveez Rehman
    yesterday










  • i have added this but its still giving the same error
    – Tajveez Rehman
    23 hours ago














0












0








0






You need to add this below code in your ParentProductId.php file :



protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}





share|improve this answer












You need to add this below code in your ParentProductId.php file :



protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Rohan HapaniRohan Hapani

5,87721662




5,87721662












  • Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
    – Tajveez Rehman
    yesterday










  • i have added this but its still giving the same error
    – Tajveez Rehman
    23 hours ago


















  • Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
    – Tajveez Rehman
    yesterday










  • i have added this but its still giving the same error
    – Tajveez Rehman
    23 hours ago
















Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday




Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday












i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago




i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago










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%2f256904%2fcustom-column-in-product-grid-not-being-filtered%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