From 3cc0db727b95b5e2f0b9ffc2666080b309296419 Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 11:49:02 +0200 Subject: [PATCH 1/7] change configuration array to put searchInput for columns in definition --- src/Datatables.php | 1 - src/View/Helper/DatatableHelper.php | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Datatables.php b/src/Datatables.php index b8cf089..5c59384 100644 --- a/src/Datatables.php +++ b/src/Datatables.php @@ -17,4 +17,3 @@ public static function postLinkMethods() ]; } } - \ No newline at end of file diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index 1c7e2e6..eda4e10 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -524,8 +524,9 @@ protected function processColumnTypeSearch() $this->searchHeadersTypes = $this->getConfig('searchHeadersTypes'); } if ($this->searchHeadersTypes === null || $this->searchHeadersTypes == []) { - $this->searchHeadersTypes = $this->fillDefaulTypes($this->dataKeys); + $this->searchHeadersTypes = $this->fillTypes($this->dataKeys); } + $rows = []; foreach ($this->searchHeadersTypes as $definition) { $parts = []; @@ -709,7 +710,7 @@ public function getTableHeaders( */ public function setTableTypeSearch(?array $tableSearchHeaders = null): void { - $defaultTypeSearch = $this->fillDefaulTypes($this->dataKeys); + $defaultTypeSearch = $this->fillTypes($this->dataKeys); if ($tableSearchHeaders === null) { $this->searchHeadersTypes = $defaultTypeSearch; } elseif (count($tableSearchHeaders) !== count($this->dataKeys)) { @@ -736,14 +737,22 @@ public function getSearchHedadersTypes() * @param array $datakeys Number of columns in searchable columns * @return array */ - protected function fillDefaulTypes(array $datakeys): array + protected function fillTypes(array $datakeys): array { $searchTypes = []; - foreach ($datakeys as $key) { + foreach ($datakeys as $name => $key) { + if (isset($key['searchable']) && $key['searchable'] == 'false') { $searchTypes[] = []; } else { - $searchTypes[] = ['type' => 'input', 'data' => []]; + if (isset($key['searchInput'])) { + $searchTypes[] = [ + 'type' => $key['searchInput']['type'], + 'data' => (isset($key['searchInput']['options'])?$key['searchInput']['options']:[]), + ]; + } else { + $searchTypes[] = ['type' => 'input', 'data' => []]; + } } } From c02ef19ad964f20fa1875f47ed6f44dcfad3e993 Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 13:10:50 +0200 Subject: [PATCH 2/7] delete setTableTypeSearch que configuration in coluns definition --- src/View/Helper/DatatableHelper.php | 47 +++++++++-------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index eda4e10..b48e550 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -120,8 +120,8 @@ class DatatableHelper extends Helper break; case 'date': - cell.html('
') - $('#from'+colIdx).datepicker() + cell.html('
') + $('#from'+colIdx) .on('change', function () { if($('#to'+colIdx).val() !== '') { api.column(colIdx).search($('#from' + colIdx).val() + '|' + $('#to' + colIdx).val()).draw(); @@ -129,8 +129,7 @@ class DatatableHelper extends Helper api.column(colIdx).search($('#from' + colIdx).val() + '|').draw(); } }); - $('#to'+colIdx).datepicker() - + $('#to'+colIdx) .on('change', function () { if($('#from'+colIdx).val() !== '') { api.column(colIdx).search($('#from'+colIdx).val() + '|' + $('#to'+colIdx).val()).draw(); @@ -255,11 +254,21 @@ class DatatableHelper extends Helper }); dt.css(:tableCss); - if( jQuery.isFunction( 'select2' ) ) { + if( $.isFunction( 'select2' ) ) { $(function(){ $(function(){ // for execute the select2 plugin after all events are loaded $('.form-select-multiple').select2(); + + }); + }); + } + if ($.isFunction( 'datepicker' )) { + $(function(){ + $(function(){ + // for execute the select2 plugin after all events are loaded + $('.datepicker').datepicker(); + }); }); } @@ -702,34 +711,6 @@ public function getTableHeaders( return $this->Html->tableHeaders($tableHeaders, $headersAttrsTr, $headersAttrsTh); } - /** - * Put Definition of types of search in headers - * - * @param array|null $tableSearchHeaders - array of search headers - * @return void - */ - public function setTableTypeSearch(?array $tableSearchHeaders = null): void - { - $defaultTypeSearch = $this->fillTypes($this->dataKeys); - if ($tableSearchHeaders === null) { - $this->searchHeadersTypes = $defaultTypeSearch; - } elseif (count($tableSearchHeaders) !== count($this->dataKeys)) { - $this->searchHeadersTypes = $tableSearchHeaders + $defaultTypeSearch; - ksort($this->searchHeadersTypes); - } else { - $this->searchHeadersTypes = $tableSearchHeaders; - } - } - - /** - * Get variable with type of search in headers - * - * @return array - */ - public function getSearchHedadersTypes() - { - return $this->searchHeadersTypes; - } /** * Fill default types for search headers From edf79a296220f6f33aac7b42f32ef19a3fb5cbcd Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 15:34:55 +0200 Subject: [PATCH 3/7] timeout 3 seconds --- src/View/Helper/DatatableHelper.php | 61 +++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index b48e550..ca132d3 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -66,7 +66,6 @@ class DatatableHelper extends Helper let columnsSearch = :searchTypes; - const execute = null; // For each column api .columns() @@ -120,8 +119,9 @@ class DatatableHelper extends Helper break; case 'date': - cell.html('
') + cell.html('
') $('#from'+colIdx) + ,datepicker() .on('change', function () { if($('#to'+colIdx).val() !== '') { api.column(colIdx).search($('#from' + colIdx).val() + '|' + $('#to' + colIdx).val()).draw(); @@ -130,6 +130,7 @@ class DatatableHelper extends Helper } }); $('#to'+colIdx) + ,datepicker() .on('change', function () { if($('#from'+colIdx).val() !== '') { api.column(colIdx).search($('#from'+colIdx).val() + '|' + $('#to'+colIdx).val()).draw(); @@ -149,17 +150,23 @@ class DatatableHelper extends Helper ) .off('keyup change') .on('keyup change', function (e) { - let action = execute; + let action = exeCall; + + if(action == null || action == false) { - let execute = true; + console.log(action); + exeCall = true; + console.log(exeCall); setTimeout(function () { - let execute = false; + exeCall = false; }, :delay); } else { + console.log(exeCall); if(action == true) { return; } } + e.stopPropagation(); // Get the search value $(this).attr('title', $(this).val()); @@ -214,6 +221,7 @@ class DatatableHelper extends Helper :getDataMethod // Generic search + let exeCall = null; :searchTemplate // Datatables configuration @@ -222,7 +230,8 @@ class DatatableHelper extends Helper :columnSearchTemplate const dt = $('#:tagId'); - + + dt.DataTable({ orderCellsTop: true, fixedHeader: true, @@ -254,21 +263,11 @@ class DatatableHelper extends Helper }); dt.css(:tableCss); - if( $.isFunction( 'select2' ) ) { + if( jQuery.isFunction( 'select2' ) ) { $(function(){ $(function(){ // for execute the select2 plugin after all events are loaded $('.form-select-multiple').select2(); - - }); - }); - } - if ($.isFunction( 'datepicker' )) { - $(function(){ - $(function(){ - // for execute the select2 plugin after all events are loaded - $('.datepicker').datepicker(); - }); }); } @@ -711,6 +710,34 @@ public function getTableHeaders( return $this->Html->tableHeaders($tableHeaders, $headersAttrsTr, $headersAttrsTh); } + /** + * Put Definition of types of search in headers + * + * @param array|null $tableSearchHeaders - array of search headers + * @return void + */ + public function setTableTypeSearch(?array $tableSearchHeaders = null): void + { + $defaultTypeSearch = $this->fillTypes($this->dataKeys); + if ($tableSearchHeaders === null) { + $this->searchHeadersTypes = $defaultTypeSearch; + } elseif (count($tableSearchHeaders) !== count($this->dataKeys)) { + $this->searchHeadersTypes = $tableSearchHeaders + $defaultTypeSearch; + ksort($this->searchHeadersTypes); + } else { + $this->searchHeadersTypes = $tableSearchHeaders; + } + } + + /** + * Get variable with type of search in headers + * + * @return array + */ + public function getSearchHedadersTypes() + { + return $this->searchHeadersTypes; + } /** * Fill default types for search headers From 36f24b951a125deac81f3053bb2494e4e0fddd46 Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 17:56:34 +0200 Subject: [PATCH 4/7] Merge branch '1.next-cake4' of github.com:VictorOcio/cakephp-datatables into 1.next-cake4 --- src/View/Helper/DatatableHelper.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index ca132d3..0bb631d 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -710,25 +710,6 @@ public function getTableHeaders( return $this->Html->tableHeaders($tableHeaders, $headersAttrsTr, $headersAttrsTh); } - /** - * Put Definition of types of search in headers - * - * @param array|null $tableSearchHeaders - array of search headers - * @return void - */ - public function setTableTypeSearch(?array $tableSearchHeaders = null): void - { - $defaultTypeSearch = $this->fillTypes($this->dataKeys); - if ($tableSearchHeaders === null) { - $this->searchHeadersTypes = $defaultTypeSearch; - } elseif (count($tableSearchHeaders) !== count($this->dataKeys)) { - $this->searchHeadersTypes = $tableSearchHeaders + $defaultTypeSearch; - ksort($this->searchHeadersTypes); - } else { - $this->searchHeadersTypes = $tableSearchHeaders; - } - } - /** * Get variable with type of search in headers * From bfa6bf3c68bfc963b2680686aa7b01760ef015ba Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 18:04:23 +0200 Subject: [PATCH 5/7] fix odatepiker --- README.md | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e40db93..c469c40 100644 --- a/README.md +++ b/README.md @@ -212,30 +212,23 @@ Will produce the following script. }); ``` -## Setting the table search type. -You can configurate the input search for select or for input. -for configurate this: -```php - $typeOfSearchColumns = [ - ['type'=> 'select','data' =>[ - ['id' => '1','name' => '1'], - ['id' => '2','name' => '2'], - ] +### types of inputs to search in colunms: +Now hava 4 types of inputs: + input + select + select multiple + date + +to define the type of search need in definition of columns especificate this array: +``` +'searchInput' => [ + 'type' => '', + 'options' => [ + ['id' => 1, 'name' => 'one'], + ], ], - ['type' => 'input','data' =>''], - ['type' => 'input','data' =>''], - ['type' => 'input','data' =>''], - ['type' => 'input','data' =>''], - ['type' => 'input','data' =>''], - ]; - - $this->Datatable->setTableTypeSearch($typeOfSeachColumns); ``` -The limitation only select 1 option, and is need write all fields of search. - -A example of this array is: -
example of search select
From 9c4ebb95bedb5ce4c126f03908e5bc8a1d68a180 Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 18:04:48 +0200 Subject: [PATCH 6/7] fix datepicker --- src/View/Helper/DatatableHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index 0bb631d..c28ad20 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -121,7 +121,7 @@ class DatatableHelper extends Helper case 'date': cell.html('
') $('#from'+colIdx) - ,datepicker() + .datepicker() .on('change', function () { if($('#to'+colIdx).val() !== '') { api.column(colIdx).search($('#from' + colIdx).val() + '|' + $('#to' + colIdx).val()).draw(); @@ -130,7 +130,7 @@ class DatatableHelper extends Helper } }); $('#to'+colIdx) - ,datepicker() + .datepicker() .on('change', function () { if($('#from'+colIdx).val() !== '') { api.column(colIdx).search($('#from'+colIdx).val() + '|' + $('#to'+colIdx).val()).draw(); From 1fd30d44c3bc660ee58a8f87477eee97502dc417 Mon Sep 17 00:00:00 2001 From: Victor Ocio Date: Fri, 15 Jul 2022 18:08:07 +0200 Subject: [PATCH 7/7] out console.log --- src/View/Helper/DatatableHelper.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index c28ad20..6e68187 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -154,14 +154,11 @@ class DatatableHelper extends Helper if(action == null || action == false) { - console.log(action); exeCall = true; - console.log(exeCall); setTimeout(function () { exeCall = false; }, :delay); } else { - console.log(exeCall); if(action == true) { return; }