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:
-
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..6e68187 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('
')
- $('#from'+colIdx).datepicker()
+ cell.html('
')
+ $('#from'+colIdx)
+ .datepicker()
.on('change', function () {
if($('#to'+colIdx).val() !== '') {
api.column(colIdx).search($('#from' + colIdx).val() + '|' + $('#to' + colIdx).val()).draw();
@@ -129,8 +129,8 @@ class DatatableHelper extends Helper
api.column(colIdx).search($('#from' + colIdx).val() + '|').draw();
}
});
- $('#to'+colIdx).datepicker()
-
+ $('#to'+colIdx)
+ .datepicker()
.on('change', function () {
if($('#from'+colIdx).val() !== '') {
api.column(colIdx).search($('#from'+colIdx).val() + '|' + $('#to'+colIdx).val()).draw();
@@ -150,17 +150,20 @@ 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;
+ exeCall = true;
setTimeout(function () {
- let execute = false;
+ exeCall = false;
}, :delay);
} else {
if(action == true) {
return;
}
}
+
e.stopPropagation();
// Get the search value
$(this).attr('title', $(this).val());
@@ -215,6 +218,7 @@ class DatatableHelper extends Helper
:getDataMethod
// Generic search
+ let exeCall = null;
:searchTemplate
// Datatables configuration
@@ -223,7 +227,8 @@ class DatatableHelper extends Helper
:columnSearchTemplate
const dt = $('#:tagId');
-
+
+
dt.DataTable({
orderCellsTop: true,
fixedHeader: true,
@@ -524,8 +529,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 = [];
@@ -701,25 +707,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->fillDefaulTypes($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
*
@@ -736,14 +723,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' => []];
+ }
}
}