In my module, I use the Listing (grid) UI component to render data from an array. The data for the grid is provided by a DataProvider.php class getData() method.
For some reason, when I use a simple testing array, the data is properly rendered. When I use the actual array that I want to use, the grid displays the message:
We couldn't find any records.
I am very sure that both arrays have the same format, so both should work. Using print_r()
to print the arrays, they look identical in format. gettype()
returns array
for both arrays.
My DataProvider.php:
public function getData()
{
$orderIds = $this->_registry->registry("orderids");
foreach ((array)$orderIds as $orderId) {
$order = $this->_order->load($orderId);
$orderInfo[] = [ // This array doesn't work
"entity_id" => $order->getId(),
"customer_firstname" => $order->getCustomerFirstname(),
"customer_lastname" => $order->getCustomerLastname(),
"customer_email" => $order->getCustomerEmail(),
];
}
$test[] = [ // This test array works
"entity_id" => 1,
"customer_firstname" => "Foo",
"customer_lastname" => "Bar",
"customer_email" => "foo@bar.com",
];
$data = [
'totalRecords' => count($orderInfo), // $test works, $orderInfo doesn't
'items' => array_values($orderInfo), // $test works, $orderInfo doesn't
];
/** @var ModifierInterface $modifier */
foreach ($this->modifiersPool->getModifiersInstances() as $modifier) {
$data = $modifier->modifyData($data);
}
return $data;
}
Short description of the code: Order IDs are stored in the registry, a foreach()
loop loops over every order ID and loads the order objects for those IDs, order data is stored in the $orderInfo
array, which should be used to provide data to the grid.
entity_id
being string. Try changing"entity_id" => $order->getId(),
to"entity_id" => (int)$order->getId(),
and see if that helps.$test
array.