3

I am creating an admin module. I have implemented a section where using a listing ui-component, i present some data from DB to the user.

I want to create a table using the same css style with the listing but this time i want my data to be loaded from a simple array.(possibly from a simple block class???)

My main concern is the style of the table. I want to use the same theme.

asked Feb 23, 2016 at 9:46

1 Answer 1

1

With ui components you just add another column and specify the class where your array is returned, i.e:

<actionsColumn name="Rerun" class="Vendor\Module\Ui\Component\Listing\Column\MyArray">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="indexField" xsi:type="string">id</item>
 <item name="urlEntityParamName" xsi:type="string">id</item>
 </item>
 </argument>
</actionsColumn>

and in Vendor\Module\Ui\Component\Listing\Column\MyArray.php you extend from Magento\Ui\Component\Listing\Columns\Column and return your array inside prepareDataSource method:

class MyArray extends Column
{
 /**
 * URL builder
 *
 * @var \Magento\Framework\UrlInterface
 */
 public $_urlBuilder;
 /**
 * @param ContextInterface $context
 * @param UiComponentFactory $uiComponentFactory
 * @param UrlInterface $urlBuilder
 * @param array $components
 * @param array $data
 */
 public function __construct(
 ContextInterface $context,
 UiComponentFactory $uiComponentFactory,
 UrlInterface $urlBuilder,
 array $components = [],
 array $data = []
 ) {
 $this->_urlBuilder = $urlBuilder;
 parent::__construct($context, $uiComponentFactory, $components, $data);
 }
 /**
 * Prepare Data Source
 *
 * @param array $dataSource
 * @return array
 */
 public function prepareDataSource(array $dataSource)
 {
 if (isset($dataSource['data']['items'])) {
 foreach ($dataSource['data']['items'] as & $item) {
 ...
 }
 }
 return $dataSource;
 }
}
answered Sep 20, 2016 at 15:00
1
  • the question is how you can use an array to show data in grid instead of database collection Commented Jul 9, 2019 at 6:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.