0

How to create a listing grid using UI component in the backend without a database ?

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Sep 4, 2019 at 3:36
3
  • do u want to get data from array?? Commented Sep 4, 2019 at 4:59
  • anyway, Just don't use the database, please give me a solution. Thank for reply. Commented Sep 4, 2019 at 5:05
  • please Check My Answer...... Commented Sep 4, 2019 at 5:22

1 Answer 1

0

in Your

Vendor\Module\Ui\DataProvider\DataProvider.php

use Magento\Framework\App\Request\Http;
use Magento\Ui\DataProvider\AbstractDataProvider;
/**
 * Class DataProvider
 */
class DataProvider extends AbstractDataProvider
{
 /**
 * @var \Magento\Ui\DataProvider\AddFieldToCollectionInterface[]
 */
 private $addFieldStrategies;
 /**
 * @var \Magento\Ui\DataProvider\AddFilterToCollectionInterface[]
 */
 private $addFilterStrategies;
 /**
 * Media path to extension images
 *
 * @var string
 */
 private $collectionFactory;
 /**
 * Media path to extension images
 *
 * @var string
 */
 private $saveImage;
 /**
 * Construct
 *
 * DataProvider constructor.
 * @param string $name
 * @param string $primaryFieldName
 * @param string $requestFieldName
 */
 public function __construct(
 \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder,
 $name,
 $primaryFieldName,
 $requestFieldName,
 Http $request,
 CollectionFactory $collectionFactory,
 array $meta = [],
 array $data = []
 ) {
 $this->searchCriteriaBuilder = $searchCriteriaBuilder;
 $this->request = $request;
 parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
 }
 /**
 * Preparing Collection For Grid
 *
 * @return Array
 */
 public function getCollection()
 {
 //Put Your Data in this Variable
 $data = 
 //Default Objects
 $pagesize = intval($this->request->getParam('paging')['pageSize']);
 $pageCurrent = intval($this->request->getParam('paging')['current']);
 $pageoffset = ($pageCurrent - 1) * $pagesize;
 return [
 'totalRecords' => count($data),
 'items' => array_slice($data, $pageoffset, $pageoffset + $pagesize),
 ];
 }
 /**
 * Return Prepared Data To Admin Grid
 *
 * @return AbstractDataProvider
 */
 public function getData()
 {
 if (!$this->getCollection()) {
 $this->getCollection();
 }
 return $this->getCollection();
 }
 /**
 * Adding Filters To Grid Collection
 *
 */
 public function addFilter(\Magento\Framework\Api\Filter $filter)
 {
 $this->searchCriteriaBuilder->addFilter($filter);
 }
 /**
 * Adding Order To Grid Collection
 *
 */
 public function addOrder($field, $direction)
 {
 $this->searchCriteriaBuilder->addSortOrder($field, $direction);
 }
 /**
 * Set Limit To Admin Collection
 *
 */
 public function setLimit($offset, $size)
 {
 $this->searchCriteriaBuilder->setPageSize($size);
 $this->searchCriteriaBuilder->setCurrentPage($offset);
 }
}

Now in

Vendor\Module\view\adminhtml\ui_component\frontname_module_controller.xml

<argument name="dataProvider" xsi:type="configurableObject">
 <argument name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\DataProvider.</argument>
 </argument>

Hope this will help You

answered Sep 4, 2019 at 5:20
9
  • Please give me full solution. Thank you. Commented Sep 4, 2019 at 6:35
  • what type of data you want to show in Grid Commented Sep 4, 2019 at 6:37
  • simply text. I just need a grid. Commented Sep 4, 2019 at 6:39
  • ho much coloums do u have how mays rows you want then i can give you a Good solution Commented Sep 4, 2019 at 6:42
  • maybe 5 columns. Commented Sep 4, 2019 at 6:44

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.