2

I use in my decision the answer that was in this question Magento 2 Custom Collection

Everything works fine, but how to filter data when they are searched?

My code

$collection = $this->_postFactory->create()->getCollection();

    $collection2 = $this->_purchaseListCollection;

    foreach ($collection->getData() as $key => $data) {
        $data['model_number'] = 'tested'.$key;
        $collection2->addItem(
            new \Magento\Framework\DataObject($data)
        );
    }

    $this->setCollection($collection2);

    return parent::_prepareCollection();

Code create table

  $this->addColumn(
        'model_number',
        [
            'header'            => __('Model number'),
            'index'             => 'model_number',
            'sortable'          => true,
            'type'              => 'text',
            'escape'            => true,
            'header_css_class'  => 'col-value',
            'column_css_class'  => 'col-value',
        ]
    );

My code on model/resourceModel collection

namespace Magento\PurchaseWizard\Model\ResourceModel\PurchaseList;

use Magento\Framework\Data\Collection as DataCollection;
class EmptyCollection extends DataCollection
{

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.