From e2d59391824bdb6820bb17b2449d87204f0902aa Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Tue, 12 Jul 2022 13:44:54 +0200 Subject: [PATCH 1/2] new funcionality no need fill search array only than not input type --- src/View/Helper/DatatableHelper.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index ba6aa76..8796496 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -394,16 +394,14 @@ public function getDatatableScript(string $tagId): string ] ); - if ($this->getConfig('columnSearch')) - { + if ($this->getConfig('columnSearch')) { $columnSearchTemplate = Text::insert( $this->columnSearchHeaderTemplate, [ 'tagId' => $tagId, ] - ); - //$columnSearchTemplate = sprintf($this->columnSearchHeaderTemplate, $tagId, $tagId); + //$columnSearchTemplate = sprintf($this->columnSearchHeaderTemplate, $tagId, $tagId); } else { $columnSearchTemplate = ''; } @@ -436,7 +434,6 @@ public function getDatatableScript(string $tagId): string 'columnSearch' => $this->getConfig('columnSearch') ? $this->columnSearchTemplate : '', 'tableCss' => json_encode($this->getConfig('tableCss')), ] - ); } @@ -461,7 +458,6 @@ protected function validateConfigurationOptions() */ protected function processColumnTypeSearch() { - $this->setTableTypeSearch($this->getConfig('searchHeadersType')); if ($this->searchHeadersTypes === null) { throw new MissConfiguredException(__('Search headers type not configured')); } @@ -649,12 +645,12 @@ public function getTableHeaders( */ public function setTableTypeSearch(?array $tableSearchHeaders = null): void { + $defaultTypeSearch = $this->fillDefaulTypes(count($this->dataKeys)); if ($tableSearchHeaders === null) { - $this->searchHeadersTypes = $this->fillDefaulTypes(count($this->dataKeys)); - } elseif (count($tableSearchHeaders) != count($this->dataKeys)) { - throw new MissConfiguredException( - __('Number of columns in search headers must be equal to number of columns in searchable columns') - ); + $this->searchHeadersTypes = $defaultTypeSearch; + } elseif (count($tableSearchHeaders) !== count($this->dataKeys)) { + $this->searchHeadersTypes = $tableSearchHeaders + $defaultTypeSearch; + ksort($this->searchHeadersTypes); } else { $this->searchHeadersTypes = $tableSearchHeaders; } @@ -676,12 +672,13 @@ public function getSearchHedadersTypes() * @param int $count Number of columns in searchable columns * @return array */ - private function fillDefaulTypes(int $count): array + protected function fillDefaulTypes(int $count): array { $searchTypes = []; for ($i = 0; $i < $count; $i++) { $searchTypes[] = ['type' => 'input', 'data' => []]; } + return $searchTypes; } } From 9d2c1b83bc1d9e8fb65da41a158ef31af9f9bc82 Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Tue, 12 Jul 2022 14:13:09 +0200 Subject: [PATCH 2/2] fix initialitation array defaults --- src/View/Helper/DatatableHelper.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index 8796496..73a3233 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -394,14 +394,16 @@ public function getDatatableScript(string $tagId): string ] ); - if ($this->getConfig('columnSearch')) { + if ($this->getConfig('columnSearch')) + { $columnSearchTemplate = Text::insert( $this->columnSearchHeaderTemplate, [ 'tagId' => $tagId, ] + ); - //$columnSearchTemplate = sprintf($this->columnSearchHeaderTemplate, $tagId, $tagId); + //$columnSearchTemplate = sprintf($this->columnSearchHeaderTemplate, $tagId, $tagId); } else { $columnSearchTemplate = ''; } @@ -434,6 +436,7 @@ public function getDatatableScript(string $tagId): string 'columnSearch' => $this->getConfig('columnSearch') ? $this->columnSearchTemplate : '', 'tableCss' => json_encode($this->getConfig('tableCss')), ] + ); } @@ -458,10 +461,12 @@ protected function validateConfigurationOptions() */ protected function processColumnTypeSearch() { - if ($this->searchHeadersTypes === null) { - throw new MissConfiguredException(__('Search headers type not configured')); + if ($this->searchHeadersTypes === null || $this->searchHeadersTypes == []) { + $this->searchHeadersTypes = $this->getConfig('searchHeadersTypes'); + } + if ($this->searchHeadersTypes === null || $this->searchHeadersTypes == []) { + $this->searchHeadersTypes = $this->fillDefaulTypes(count($this->dataKeys)); } - $rows = []; foreach ($this->searchHeadersTypes as $definition) { $parts = [];