Open tajveez-73 opened 2 years ago
That should work. I can apply filters to grids with an array source. I'll have too look into this.
Hey @Vinai
I think I found the problem.
When the grid is prepared, the columsn/definition is extracted using \Hyva\Admin\Model\GridSourceType\ArrayProviderGridSourceType::getColumnKeys
and \Hyva\Admin\Model\GridSourceType\ArrayProviderGridSourceType::getColumnDefinition
.
Each of those two calls \Hyva\Admin\Model\GridSourceType\ArrayProviderGridSourceType::getFirstRow
internally, which in turn calls \Hyva\Admin\Model\GridSourceType\ArrayProviderGridSourceType::fetchData
with some dummy search criteria:
$searchCriteria = $this->searchCriteriaBuilder->setPageSize(1)->setCurrentPage(1)->create();
return values($this->gridSourceDataAccessor->unbox($this->fetchData($searchCriteria)))[0] ?? [];
The problem here is, that fetchData
with memoize the results, but it does not distinguish between the dummy search criteria and the real one.
So when the real search criteria is passed to fetchData
, the method will just return the memoized data from the dummy search criteria.
Locally I solved it with a quick and dirty patch, adding a forceRefresh
parameter. (but I don't think this is a very good solution):
--- Model/GridSourceType/ArrayProviderGridSourceType.php
+++ Model/GridSourceType/ArrayProviderGridSourceType.php
@@ -136,9 +136,9 @@
*
* @return RawGridSourceContainer
*/
- public function fetchData(SearchCriteriaInterface $searchCriteria): RawGridSourceContainer
+ public function fetchData(SearchCriteriaInterface $searchCriteria, bool $forceRefresh = true): RawGridSourceContainer
{
- if (!isset($this->memoizedGridData)) {
+ if ($forceRefresh || !isset($this->memoizedGridData)) {
$provider = $this->arrayProviderFactory->create($this->arrayProviderClass);
map(function (HyvaGridSourceProcessorInterface $processor) use ($provider, $searchCriteria): void {
@@ -177,7 +177,7 @@
private function getFirstRow(): array
{
$searchCriteria = $this->searchCriteriaBuilder->setPageSize(1)->setCurrentPage(1)->create();
- return values($this->gridSourceDataAccessor->unbox($this->fetchData($searchCriteria)))[0] ?? [];
+ return values($this->gridSourceDataAccessor->unbox($this->fetchData($searchCriteria, false)))[0] ?? [];
}
public function extractTotalRowCount(RawGridSourceContainer $rawGridData): int
Hi renttek
I am also trying to add the filter with the same process as adding below filter .
I am calling the grid data with
Thanks
Hi,
I am making a Hyva grid with
source
asarrayProvider
and have givenfilters
tag in the XML file like followingthe filters are showing on the grid they aren't working. Is this how we add filters to the grid with the
source
asarrayProvider
or am I missing something.Thanks.