Skip to content

Admin Listing – Display non-db data

I’m facing a problem and i didn’t find solution on Internet or on Adobe Documentation. I’m using Magento 2.4.7-p3

I would like to display all of the cron definitions in an admin grid listing. About getting the data, i have no problem, i’m calling the Class MagentoCronModelConfigInterface and then getJobs method to get all cron definitions. It works fine.

My problem is : i don’t have any clue on how to display non-db data in an admin listing. I followed a tutorial here : https://www.azguards.com/magento/customizing-magento-2-admin-grid-using-ui-components/, my current code is very similar to this.
At first sight, it seems great, but the code presented in this tutorial as some flaws:

  • Pagination doesn’t work, i have to do something like that
$pagesize = intval($this->request->getParam('paging')['pageSize'] ?? 20);
$pageCurrent = intval($this->request->getParam('paging')['current'] ?? 1);
$pageoffset = ($pageCurrent - 1)*$pagesize;

return [
  'totalRecords' => count($items),
  'items' => array_slice($items, $pageoffset, $pagesize),
];
  • Filters and ordering don’t work too.

So my questions are

  • Are Magento Admin Grid designed to handle non-db items/entities?
  • Could the method presented above work, provided that you reinvent the wheel in certain parts (pagination, filters, etc.)?
  • Is it possible to create a Model Triad (Model/ResourceModel/Collection) which does not rely on db data, that i could use in my Admin Grid?

Thanks a lot for your responses, i’m available if you have any question 🙂