I need to override module-catalog\view\adminhtml\ui_component\product_listing.xml
file in my custom module. I have copy the core magento file in my module at view\adminhtml\ui_component
but its not working. is there anything else i have to do.
-
add sourse & collection mode in di.xml & add same xml in your custom list xml– Birjitsinh ZalaCommented Jan 18, 2018 at 7:07
-
Did not get you what you are try to say– Pramod Kumar SharmaCommented Jan 18, 2018 at 7:10
-
fist you have to assing product collection in di.xml after use that source collection in your custom list xml– Birjitsinh ZalaCommented Jan 18, 2018 at 7:12
-
magento.stackexchange.com/questions/209804/…– Birjitsinh ZalaCommented Jan 18, 2018 at 7:12
-
vendor_department_addform_data_source this id get form di.xml– Birjitsinh ZalaCommented Jan 18, 2018 at 7:13
|
Show 2 more comments
1 Answer
<?xml version="1.0"?>
<!--
/**
* @copyright Copyright (c) 2016 www.magebuzz.com
*/
-->
<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" class="Magento\Catalog\Ui\Component\Listing\Columns">
<column name="custom_field">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="add_field" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Custom Field</item>
<item name="sortOrder" xsi:type="number">75</item>
</item>
</argument>
</column>
</columns>
</listing>
Then created the UI class under [COMPANY]/[MODULE]/Ui/Component/Listing/Column/Status.php
<?php
namespace RLTS\Helloworld\Ui\Component\Listing\Column;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
class Category extends \Magento\Ui\Component\Listing\Columns\Column
{
public function prepareDataSource(array $dataSource)
{
$fieldName = $this->getData('name');
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
//print_r($item);die;
$productId=$item['entity_id'];
//$product=$this->_productloader->create()->load($p_id);
//$product = $objectManager->get('Magento\Catalog\Model\Product')->load($p_id);
//$productId = $p_id;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
$cats = $product->getCategoryIds();
//$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categories=array();
if(count($cats) ){
foreach($cats as $cat){
$category = $objectManager->create('Magento\Catalog\Model\Category')->load($cat);
$categories[]=$category->getName();
}
}
$item[$fieldName]=implode(',',$categories);
}
}
return $dataSource;
}
}
This is for just DEMO
<column name="amount" class="M [COMPANY]\[MODULE]\Ui\Component\Listing\Column\Status">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="sortOrder" xsi:type="number">3</item>
<item name="label" translate="true" xsi:type="string">Amount</item>
</item>
</argument>
</column>
namespace [COMPANY]\[MODULE]\Ui\Component\Listing\Column;
use \Magento\Sales\Api\OrderRepositoryInterface;
use \Magento\Framework\View\Element\UiComponent\ContextInterface;
use \Magento\Framework\View\Element\UiComponentFactory;
use \Magento\Ui\Component\Listing\Columns\Column;
use \Magento\Framework\Api\SearchCriteriaBuilder;
class Status extends Column
{
protected $_orderRepository;
protected $_searchCriteria;
public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = [], array $data = [])
{
$this->_orderRepository = $orderRepository;
$this->_searchCriteria = $criteria;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$status = $order->getData("export_status");
switch ($status) {
case "0":
$export_status = "No";
break;
case "1";
$export_status = "Yes";
break;
default:
$export_status = "Failed";
break;
}
// $this->getData('name') returns the name of the column so in this case it would return export_status
$item[$this->getData('name')] = $export_status;
}
}
return $dataSource;
}
}
-
This code will add new column in the grid but what i am trying to do is to add inline Edit in product list grid. I have worked on core file but now i want to use that core file in my module. Commented Jan 18, 2018 at 7:26
-
<column name="amount" class="[COMPANY][MODULE]\Ui\Component\Listing\Columnt"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="filter" xsi:type="string">text</item> <item name="sorting" xsi:type="string">asc</item> <item name="sortOrder" xsi:type="number">3</item> <item name="label" translate="true" xsi:type="string">Amount</item> </item> </argument> </column> Commented Jan 18, 2018 at 7:28
-
-
Thanks for your answer but i don't this kind of functionality. I simply want to override product_listing.xml Commented Jan 18, 2018 at 9:15
-
<column name="custom_field"> this for culumns name available in product table then class="M [COMPANY][MODULE]\Ui\Component\Listing\Column\Status"> not require and also not require below php code Commented Jan 18, 2018 at 9:18