2
2
3
3
namespace Yajra \DataTables \Html ;
4
4
5
- use Yajra \DataTables \Html \HtmlBuilder ;
6
5
use Illuminate \Contracts \Config \Repository ;
7
6
use Illuminate \Contracts \View \Factory ;
8
7
use Illuminate \Support \Collection ;
@@ -30,6 +29,11 @@ class Builder
30
29
const SELECT_ITEMS_COLUMN = 'column ' ;
31
30
const SELECT_ITEMS_CELL = 'cell ' ;
32
31
32
+ /**
33
+ * The default type to use for the DataTables javascript.
34
+ */
35
+ protected static string $ jsType = 'text/javascript ' ;
36
+
33
37
/**
34
38
* @var Collection<int, \Yajra\DataTables\Html\Column>
35
39
*/
@@ -73,6 +77,22 @@ public function __construct(public Repository $config, public Factory $view, pub
73
77
];
74
78
}
75
79
80
+ /**
81
+ * Set the default type to module for the DataTables javascript.
82
+ */
83
+ public static function useVite (): void
84
+ {
85
+ static ::$ jsType = 'module ' ;
86
+ }
87
+
88
+ /**
89
+ * Set the default type to text/javascript for the DataTables javascript.
90
+ */
91
+ public static function useWebpack (): void
92
+ {
93
+ static ::$ jsType = 'text/javascript ' ;
94
+ }
95
+
76
96
/**
77
97
* Generate DataTable javascript.
78
98
*
@@ -83,7 +103,9 @@ public function __construct(public Repository $config, public Factory $view, pub
83
103
public function scripts (string $ script = null , array $ attributes = ['type ' => 'text/javascript ' ]): HtmlString
84
104
{
85
105
$ script = $ script ?: $ this ->generateScripts ();
86
- $ attributes = $ this ->html ->attributes ($ attributes );
106
+ $ attributes = $ this ->html ->attributes (
107
+ array_merge ($ attributes , ['type ' => static ::$ jsType ])
108
+ );
87
109
88
110
return new HtmlString ("<script {$ attributes }> $ script</script> " );
89
111
}
0 commit comments