I am trying to show all of the postal codes in my grid from the array in column but it showing only the last one.
Array
(
[0] => Array
(
[from_postalcode] => 123
[to_postalcode] => 123
[record_id] => 0
[initialize] => true
)
[1] => Array
(
[record_id] => 1
[from_postalcode] => 1234
[to_postalcode] => 1234
)
)
And below is my Code:
class PostalCodeArea extends MagentoUiComponentListingColumnsColumn
{
/**
* @param MagentoFrameworkViewElementUiComponentContextInterface $context
* @param MagentoFrameworkViewElementUiComponentFactory $uiComponentFactory
* @param array $components = []
* @param array $data = []
*/
public function __construct(
MagentoFrameworkViewElementUiComponentContextInterface $context,
MagentoFrameworkViewElementUiComponentFactory $uiComponentFactory,
array $components = [],
array $data = []
)
{
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$countryCodes = [];
$FromToPostalCode = json_decode($item['from_to_postalcode'],true);
foreach ($FromToPostalCode as $key){
foreach ($key as $array => $code) {
$item['postalcode_area'] = $code;
}
}
}
}
return $dataSource;
}
}
I do not really know what to do and I am confused and tired.
Looking for help.
Thanks.