Skip to content

Commit 054ade7

Browse files
authored
Merge pull request #40 from JulianDroog/1.next-cake4
Added possibility to have 2 libaries for mulitselect
2 parents 1eb0bee + 8dcb34e commit 054ade7

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,12 @@ $this->Datatable->setCallbackCreatedRow(
358358
}
359359
}'
360360
);
361-
``
361+
```
362+
363+
# Change library of multiselect
364+
365+
The default is jquery-ui multiselect, if you want to change this you can change it in the configuration or like the code example below
366+
367+
```php
368+
$this->Datatable->getInstance()->setConfig('multiSelectType', 'select2');
369+
```

src/Datatable/Datatable.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Datatable
2020
{
2121
use InstanceConfigTrait;
2222

23+
2324
/**
2425
* @var string
2526
*/
@@ -35,6 +36,11 @@ class Datatable
3536
*
3637
* @var array<string, mixed>
3738
*/
39+
40+
41+
const MULTI_SELECT_TYPE_SELECT2 = 'select2';
42+
const MULTI_SELECT_TYPE_JQUERY_UI = 'jquery-ui';
43+
3844
protected $_defaultConfig = [
3945
'processing' => true,
4046
'serverSide' => true,
@@ -77,6 +83,7 @@ class Datatable
7783
'headersAttrsTr' => [],
7884
'headersAttrsTh' => [],
7985
],
86+
'multiSelectType' => self::MULTI_SELECT_TYPE_SELECT2,
8087
'rowActions' => [
8188
'name' => 'actions',
8289
'orderable' => 'false',
@@ -326,27 +333,25 @@ class Datatable
326333
:onCompleteCallback
327334
//column search
328335
:columnSearch
336+
337+
:multiSelectCallback
329338
},
330339
});
331340
332341
dt.css(:tableCss);
333-
if( jQuery.isFunction( 'select2' ) ) {
334-
$(function(){
335-
$(function(){
336-
// for execute the select2 plugin after all events are loaded
337-
$('.form-select-multiple').select2();
338-
});
339-
});
340-
}
341-
342-
function validateDate(text) {
343-
text = text.replaceAll("/","-");
344-
var re = /^(\d{4}(-)\d{2}(-)\d{2}|\d{2}(-)\d{2}(-)\d{4})$/;
345-
return re.test(text);
346-
}
347342
});
348343
DATATABLE_CONFIGURATION;
349344

345+
protected $datatableJqueryUITemplate = <<<JQUERYUI_CONFIGURATION
346+
if ($.fn.multiselect) { $(function(){ $('.form-select-multiple').multiselect(); }); }
347+
JQUERYUI_CONFIGURATION;
348+
349+
350+
protected $datatableSelect2Template = <<<SELECT2_CONFIGURATION
351+
if($.fn.select2) { $(function(){ $('.form-select-multiple').select2();}); }
352+
SELECT2_CONFIGURATION;
353+
354+
350355
/**
351356
* @param Helper $Helper
352357
*/
@@ -482,6 +487,7 @@ public function getDatatableScript(): string
482487
'onCompleteCallback' => $this->getConfig('onCompleteCallback') ? $this->getConfig('onCompleteCallback') : 'null',
483488
'columnSearch' => $this->getConfig('columnSearch') ? $this->columnSearchTemplate : '',
484489
'tableCss' => json_encode($this->getConfig('tableCss')),
490+
'multiSelectCallback' => $this->getConfig('multiSelectType') === 'jquery-ui' ? $this->datatableJqueryUITemplate : $this->datatableSelect2Template,
485491
];
486492

487493
if ($this->getConfig('createdRow')) {

0 commit comments

Comments
 (0)