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,26 +29,27 @@ 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
*/
36
40
public Collection $ collection ;
37
-
38
41
/**
39
42
* @var array<string, string|null>
40
43
*/
41
44
protected array $ tableAttributes = [];
42
-
43
45
/**
44
46
* @var string
45
47
*/
46
48
protected string $ template = '' ;
47
-
48
49
/**
49
50
* @var array
50
51
*/
51
52
protected array $ attributes = [];
52
-
53
53
/**
54
54
* @var string|array
55
55
*/
@@ -73,6 +73,14 @@ public function __construct(public Repository $config, public Factory $view, pub
73
73
];
74
74
}
75
75
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
+
76
84
/**
77
85
* Generate DataTable javascript.
78
86
*
@@ -83,7 +91,9 @@ public function __construct(public Repository $config, public Factory $view, pub
83
91
public function scripts (string $ script = null , array $ attributes = ['type ' => 'text/javascript ' ]): HtmlString
84
92
{
85
93
$ script = $ script ?: $ this ->generateScripts ();
86
- $ attributes = $ this ->html ->attributes ($ attributes );
94
+ $ attributes = $ this ->html ->attributes (
95
+ array_merge ($ attributes , ['type ' => static ::$ jsType ])
96
+ );
87
97
88
98
return new HtmlString ("<script {$ attributes }> $ script</script> " );
89
99
}
0 commit comments