Skip to content

Commit 54da8ed

Browse files
authored
add bootstrap4/5 support (#67)
* gh-66 Change datatables extension to bootstrap 4 * gh-66 Fix sourcepath for bootstrap 4 * gh-66 Add switch to autodetect bootstrap version * gh-66 Prepare bootstrap5 dependencies * gh-66 Re-add plugins - this line was accidentally removed in 241f749
1 parent 276e85b commit 54da8ed

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"php": ">=5.5.0",
3030
"yiisoft/yii2": "~2.0.13",
3131
"bower-asset/datatables": "~1.10.15",
32-
"bower-asset/datatables-plugins": "~1.10.15"
32+
"bower-asset/datatables-plugins": "~1.10.15",
33+
"bower-asset/datatables.net-bs4": "~1.10.15",
34+
"npm-asset/datatables.net-bs5": "~1.10.15"
3335
},
3436
"autoload": {
3537
"psr-4": {

src/assets/DataTableBootstrapAsset.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
class DataTableBootstrapAsset extends AssetBundle
1414
{
15-
public $sourcePath = '@bower/datatables-plugins/integration/bootstrap/3';
16-
1715
public $depends = [
1816
DataTableBaseAsset::class,
1917
];
@@ -22,9 +20,24 @@ public function init()
2220
{
2321
parent::init();
2422

25-
$this->depends[] = 'yii\bootstrap\BootstrapAsset';
26-
$this->css[] = 'dataTables.bootstrap.css';
27-
$this->js[] = 'dataTables.bootstrap' . (YII_ENV_DEV ? '' : '.min') . '.js';
23+
if (class_exists('yii\bootstrap\BootstrapAsset')) {
24+
$this->sourcePath = '@bower/datatables-plugins/integration/bootstrap/3';
25+
$this->depends[] = 'yii\bootstrap\BootstrapAsset';
26+
$this->css[] = 'dataTables.bootstrap.css';
27+
$this->js[] = 'dataTables.bootstrap' . (YII_ENV_DEV ? '' : '.min') . '.js';
28+
29+
} else if(class_exists('yii\bootstrap4\BootstrapAsset')) {
30+
$this->sourcePath = '@bower/datatables.net-bs4';
31+
$this->depends[] = 'yii\bootstrap4\BootstrapAsset';
32+
$this->css[] = 'css\dataTables.bootstrap4.css';
33+
$this->js[] = 'js\dataTables.bootstrap4' . (YII_ENV_DEV ? '' : '.min') . '.js';
34+
35+
} else {
36+
$this->sourcePath = '@npm/datatables.net-bs5';
37+
$this->depends[] = 'yii\bootstrap5\BootstrapAsset';
38+
$this->css[] = 'css\dataTables.bootstrap5.css';
39+
$this->js[] = 'js\dataTables.bootstrap5' . (YII_ENV_DEV ? '' : '.min') . '.js';
40+
}
2841
}
2942

3043
}

0 commit comments

Comments
 (0)