From dab310d27fe71b20a4c5fe88120bbbe079593021 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Thu, 12 Jan 2023 17:04:28 +0100 Subject: [PATCH 1/5] add tagId to inset in columnsearch --- src/Datatable/Datatable.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Datatable/Datatable.php b/src/Datatable/Datatable.php index 528afda..2deba44 100644 --- a/src/Datatable/Datatable.php +++ b/src/Datatable/Datatable.php @@ -106,7 +106,7 @@ class Datatable .columns() .eq(0) .each(function (colIdx) { - var cell = $('.filters th').eq( + var cell = $('#:tagId .filters th').eq( $(api.column(colIdx).header()).index() ); if (columnsSearch[colIdx] !== undefined) { @@ -136,7 +136,7 @@ class Datatable }); break; - case 'select' : + case 'select' : cell.html(''); columnsSearch[colIdx].data.forEach(function (data) { $( @@ -154,7 +154,7 @@ class Datatable api.column(colIdx).search(this.value).draw(); }); break; - + case 'date': title = cell.data('header') ?? ''; cell.html('
') @@ -188,8 +188,8 @@ class Datatable .off('keyup change') .on('keyup change', function (e) { let action = exeCall; - - + + if(action == null || action == false) { exeCall = true; setTimeout(function () { @@ -200,25 +200,25 @@ class Datatable return; } } - + e.stopPropagation(); // Get the search value $(this).attr('title', $(this).val()); var regexr = '({search})'; //$(this).parents('th').find('select').val(); - + var cursorPosition = this.selectionStart; // Search the column for that value api .column(colIdx) .search( - this.value != ''? - regexr.replace('{search}', + this.value != ''? + regexr.replace('{search}', '(((' + this.value + ')))'): '', this.value != '', this.value == '' ) .draw(); - + $(this) .focus()[0] .setSelectionRange(cursorPosition, cursorPosition); @@ -233,7 +233,7 @@ class Datatable protected $genericSearchTemplate = << ($this->searchHeadersTypes ?? ''), 'delay' => $this->getConfig('delay') ?? '3000', + 'tagId' => $tagId, ] ); From ee6de89ba411835b0c8dc6b5f4ffbe093772db79 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Thu, 12 Jan 2023 17:17:36 +0100 Subject: [PATCH 2/5] add tagId to insert in columnsearch --- src/Datatable/Datatable.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Datatable/Datatable.php b/src/Datatable/Datatable.php index 2deba44..9362dda 100644 --- a/src/Datatable/Datatable.php +++ b/src/Datatable/Datatable.php @@ -54,7 +54,7 @@ class Datatable 'delay' => 3000, 'definitionColumns' => [], - 'tableId' => null, + 'tableId' => '', 'headers' => [], 'fields' => [], 'headersConfig' => [ @@ -118,19 +118,19 @@ class Datatable columnsSearch[colIdx].data.forEach(function (data) { $( 'select', - $('.filters th').eq($(api.column(colIdx).header()).index()) + $('#:tagId .filters th').eq($(api.column(colIdx).header()).index()) ).append( '' ); }); $( 'select', - $('.filters th').eq($(api.column(colIdx).header()).index()) + $('#:tagId .filters th').eq($(api.column(colIdx).header()).index()) ) .on('change', function () { let select_value = $( 'select option:selected', - $('.filters th').eq($(api.column(colIdx).header()).index()) + $('#:tagId .filters th').eq($(api.column(colIdx).header()).index()) ).toArray().map(item => item.value).join(); api.column(colIdx).search(select_value).draw(); }); @@ -141,14 +141,14 @@ class Datatable columnsSearch[colIdx].data.forEach(function (data) { $( 'select', - $('.filters th').eq($(api.column(colIdx).header()).index()) + $('#:tagId .filters th').eq($(api.column(colIdx).header()).index()) ).append( '' ); }); $( 'select', - $('.filters th').eq($(api.column(colIdx).header()).index()) + $('#:tagId .filters th').eq($(api.column(colIdx).header()).index()) ) .on('change', function () { api.column(colIdx).search(this.value).draw(); @@ -183,7 +183,7 @@ class Datatable cell.html(''); $( 'input', - $('.filters th').eq($(api.column(colIdx).header()).index()) + $('#:tagId .filters th').eq($(api.column(colIdx).header()).index()) ) .off('keyup change') .on('keyup change', function (e) { From fffb5eadc36b80947e16b4e50ba1ae8e51bf7fac Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 16 Jan 2023 10:02:46 +0100 Subject: [PATCH 3/5] add config to ajaxtype url request (options: POST, GET, ...) --- src/Datatable/Datatable.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Datatable/Datatable.php b/src/Datatable/Datatable.php index 9362dda..10eb5a3 100644 --- a/src/Datatable/Datatable.php +++ b/src/Datatable/Datatable.php @@ -45,6 +45,7 @@ class Datatable //complete callback function 'onCompleteCallback' => null, 'ajaxUrl' => null, + 'ajaxType' => 'POST', 'autoWidth' => false, 'tableCss' => [ 'width' => '100%', @@ -464,6 +465,8 @@ public function setGetDataUrl($defaultUrl = null) $url = array_merge($url, ['fullBase' => true, '_ext' => 'json']); $url = $this->Helper->Url->build($url); + $ajaxType = $this->getConfig('ajaxType'); + if (!empty($this->getConfig('extraFields'))) { $extraFields = $this->processExtraFields(); //@todo change to async or anonymous js function @@ -485,7 +488,7 @@ public function setGetDataUrl($defaultUrl = null) let getData = async () => { return { url:'{$url}', - type: 'POST', + type: '{$ajaxType}', } }; GET_DATA; From d07c7936aaf80ac4ab6a8ad1460cbed61d2edae6 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 16 Jan 2023 11:25:41 +0100 Subject: [PATCH 4/5] fix selector for date ti tableId config --- src/Datatable/Datatable.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Datatable/Datatable.php b/src/Datatable/Datatable.php index 10eb5a3..22f16b8 100644 --- a/src/Datatable/Datatable.php +++ b/src/Datatable/Datatable.php @@ -158,23 +158,23 @@ class Datatable case 'date': title = cell.data('header') ?? ''; - cell.html('
') - $('#from'+colIdx) + cell.html('
') + $('#:tagId').find('#from'+colIdx) .datepicker() .on('change', function () { if($('#to'+colIdx).val() !== '') { - api.column(colIdx).search($('#from' + colIdx).val() + '|' + $('#to' + colIdx).val()).draw(); + api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|' + $('#:tagId').find('#to' + colIdx).val()).draw(); } else { - api.column(colIdx).search($('#from' + colIdx).val() + '|').draw(); + api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|').draw(); } }); - $('#to'+colIdx) + $('#:tagId').find('#to'+colIdx) .datepicker() .on('change', function () { if($('#from'+colIdx).val() !== '') { - api.column(colIdx).search($('#from'+colIdx).val() + '|' + $('#to'+colIdx).val()).draw(); + api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|' + $('#:tagId').find('#to' + colIdx).val()).draw(); } else { - api.column(colIdx).search( '|' + $('#to'+colIdx).val()).draw(); + api.column(colIdx).search( '|' + $('#:tagId').find('#to' + colIdx).val()).draw(); } }); break; From 3c83a2b0074ba69030a9a061de337476fdb063ef Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 16 Jan 2023 11:33:30 +0100 Subject: [PATCH 5/5] add options fixedHeader for enable/disable fixed header on scroll page --- src/Datatable/Datatable.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Datatable/Datatable.php b/src/Datatable/Datatable.php index 22f16b8..e5017d7 100644 --- a/src/Datatable/Datatable.php +++ b/src/Datatable/Datatable.php @@ -54,7 +54,7 @@ class Datatable ], 'delay' => 3000, 'definitionColumns' => [], - + 'fixedHeader' => true, 'tableId' => '', 'headers' => [], 'fields' => [], @@ -274,7 +274,7 @@ class Datatable dt.DataTable({ orderCellsTop: true, - fixedHeader: true, + fixedHeader: :fixedHeader, autoWidth: :autoWidth, ajax: await getData(), //searching: false, @@ -438,6 +438,7 @@ public function getDatatableScript(): string 'searchTemplate' => $searchTemplate, 'columnSearchTemplate' => $columnSearchTemplate, 'tagId' => $tagId, + 'fixedHeader' => $this->getConfig('fixedHeader') ? 'true' : 'false', 'autoWidth' => $this->getConfig('autoWidth') ? 'true' : 'false', 'pageLength' => $this->getConfig('pageLentgh') ?? '10', 'processing' => $this->getConfig('processing') ? 'true' : 'false',