22
33namespace Yajra \DataTables \Html ;
44
5- use Yajra \DataTables \Html \HtmlBuilder ;
65use Illuminate \Contracts \Config \Repository ;
76use Illuminate \Contracts \View \Factory ;
87use Illuminate \Support \Collection ;
@@ -30,6 +29,11 @@ class Builder
3029 const SELECT_ITEMS_COLUMN = 'column ' ;
3130 const SELECT_ITEMS_CELL = 'cell ' ;
3231
32+ /**
33+ * The default type to use for the DataTables javascript.
34+ */
35+ protected static string $ jsType = 'text/javascript ' ;
36+
3337 /**
3438 * @var Collection<int, \Yajra\DataTables\Html\Column>
3539 */
@@ -73,6 +77,22 @@ public function __construct(public Repository $config, public Factory $view, pub
7377 ];
7478 }
7579
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+
7696 /**
7797 * Generate DataTable javascript.
7898 *
@@ -83,7 +103,9 @@ public function __construct(public Repository $config, public Factory $view, pub
83103 public function scripts (string $ script = null , array $ attributes = ['type ' => 'text/javascript ' ]): HtmlString
84104 {
85105 $ script = $ script ?: $ this ->generateScripts ();
86- $ attributes = $ this ->html ->attributes ($ attributes );
106+ $ attributes = $ this ->html ->attributes (
107+ array_merge ($ attributes , ['type ' => static ::$ jsType ])
108+ );
87109
88110 return new HtmlString ("<script {$ attributes }> $ script</script> " );
89111 }
0 commit comments