Мне нужно объединить два столбца в сетке моей панели администратора. Это мой код.
<?php
namespace Bridge\Tradeuser\Block\Adminhtml\Customer\Grid;
use Magento\Customer\Controller\RegistryConstants;
class Owners extends \Magento\Backend\Block\Widget\Grid\Extended {
protected $_coreRegistry = null;
protected $collectionFactory;
protected $_customerFactory;
protected $_objectManager;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $collectionFactory,
\Magento\Framework\Registry $coreRegistry,
\Magento\Customer\Model\CustomerFactory $customerFactory,
\Magento\Framework\ObjectManagerInterface $objectManager,
array $data = []
) {
$this->_coreRegistry = $coreRegistry;
$this->_collectionFactory = $collectionFactory;
$this->_customerFactory = $customerFactory;
$this->_objectManager = $objectManager;
parent::__construct($context, $backendHelper, $data);
}
protected function _construct() {
parent::_construct();
$this->setId('id');
$this->setDefaultSort('id', 'desc');
$this->setUseAjax(true);
}
protected function _prepareCollection() {
$customer = $this->_customerFactory->create();
$customer = $customer->load($this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID))->getData();
$collection = $this->_objectManager->create('Bridge\Tradeuser\Model\Tradeuser')->getCollection()->addFieldToFilter(
'customer_id', $customer['entity_id']
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('id', ['header' => __('Owners'), 'width' => '100', 'index' => 'id']);
$this->addColumn('owner_first_name', ['header' => __('Owner First Name'), 'width' => '100', 'index' => 'owner_first_name', 'type' => 'text']);
$this->addColumn('owner_last_name', ['header' => __('Owner Last Name'), 'width' => '100', 'index' => 'owner_last_name', 'type' => 'text']);
$this->addColumn('owner_email', ['header' => __('Owner Email'), 'width' => '100', 'index' => 'owner_email', 'type' => 'text']);
$this->addColumn('owner_address', ['header' => __('Owner Address'), 'width' => '100', 'index' => 'owner_address', 'type' => 'text']);
$this->addColumn('owner_postcode', ['header' => __('Owner postcode'), 'width' => '100', 'index' => 'owner_postcode', 'type' => 'text']);
$this->addColumn('owner_phone', ['header' => __('Owner Phone'), 'width' => '100', 'index' => 'owner_phone', 'type' => 'text']);
$this->addColumn('owner_fax', ['header' => __('Owner Fax'), 'width' => '100', 'index' => 'owner_fax', 'type' => 'text']);
$this->addColumn('created_at', ['header' => __('Create Date'), 'width' => '100', 'index' => 'created_at', 'type' => 'date']);
return parent::_prepareColumns();
}
}
Мне нужно объединить owner_first_name
и owner_last_name
в owner_name
. Я попытался следующий код, но он выдает ошибку, как A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later.
$this->addColumn('owner_first_name',
array(
'header' => $this->__('Owner Name'),
'sortable' => true,
'index' => array('owner_first_name', 'owner_last_name'),
'type' => 'concat',
'separator' => ' ',
'filter_index' => "CONCAT(owner_first_name, ' ', owner_last_name)",
'width' => '140px',
)
);