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,26 +29,27 @@ 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 */
3640 public Collection $ collection ;
37-
3841 /**
3942 * @var array<string, string|null>
4043 */
4144 protected array $ tableAttributes = [];
42-
4345 /**
4446 * @var string
4547 */
4648 protected string $ template = '' ;
47-
4849 /**
4950 * @var array
5051 */
5152 protected array $ attributes = [];
52-
5353 /**
5454 * @var string|array
5555 */
@@ -73,6 +73,14 @@ public function __construct(public Repository $config, public Factory $view, pub
7373 ];
7474 }
7575
76+ /**
77+ * Set the default type to module or the DataTables javascript.
78+ */
79+ public static function useVite (): void
80+ {
81+ static ::$ jsType = 'module ' ;
82+ }
83+
7684 /**
7785 * Generate DataTable javascript.
7886 *
@@ -83,7 +91,9 @@ public function __construct(public Repository $config, public Factory $view, pub
8391 public function scripts (string $ script = null , array $ attributes = ['type ' => 'text/javascript ' ]): HtmlString
8492 {
8593 $ script = $ script ?: $ this ->generateScripts ();
86- $ attributes = $ this ->html ->attributes ($ attributes );
94+ $ attributes = $ this ->html ->attributes (
95+ array_merge ($ attributes , ['type ' => static ::$ jsType ])
96+ );
8797
8898 return new HtmlString ("<script {$ attributes }> $ script</script> " );
8999 }
0 commit comments