Skip to content

Commit 8053d44

Browse files
committed
Add missing setters as per docs.
https://datatables.net/reference/option/#buttons
1 parent 6c902a8 commit 8053d44

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

src/Html/Button.php

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,101 @@ public static function raw($options = [])
3939
return new static($options);
4040
}
4141

42+
/**
43+
* Set attr option value.
44+
*
45+
* @param array $value
46+
* @return $this
47+
* @see https://datatables.net/reference/option/buttons.buttons.attr
48+
*/
49+
public function attr(array $value)
50+
{
51+
$this->attributes['attr'] = $value;
52+
53+
return $this;
54+
}
55+
56+
/**
57+
* Set available option value.
58+
*
59+
* @param string $value
60+
* @return $this
61+
* @see https://datatables.net/reference/option/buttons.buttons.available
62+
*/
63+
public function available($value)
64+
{
65+
if ($this->isFunction($value)) {
66+
$this->attributes['available'] = $value;
67+
} else {
68+
$this->attributes['available'] = "function(dt, config) { $value }";
69+
}
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* Check if a given value is a function.
76+
*
77+
* @param string $value
78+
* @return bool
79+
*/
80+
protected function isFunction($value)
81+
{
82+
return substr($value, 0, 8) == 'function';
83+
}
84+
85+
/**
86+
* Set enabled option value.
87+
*
88+
* @param bool $value
89+
* @return $this
90+
* @see https://datatables.net/reference/option/buttons.buttons.enabled
91+
*/
92+
public function enabled($value = true)
93+
{
94+
$this->attributes['enabled'] = $value;
95+
96+
return $this;
97+
}
98+
99+
/**
100+
* Set init option value.
101+
*
102+
* @param string $value
103+
* @return $this
104+
* @see https://datatables.net/reference/option/buttons.buttons.init
105+
*/
106+
public function init($value)
107+
{
108+
if ($this->isFunction($value)) {
109+
$this->attributes['init'] = $value;
110+
} else {
111+
$this->attributes['init'] = "function(dt, node, config) { $value }";
112+
}
113+
114+
return $this;
115+
}
116+
117+
/**
118+
* Set key option value.
119+
*
120+
* @param string|array $value
121+
* @return $this
122+
* @see https://datatables.net/reference/option/buttons.buttons.key
123+
*/
124+
public function key($value)
125+
{
126+
$this->attributes['key'] = $value;
127+
128+
return $this;
129+
}
130+
42131
/**
43132
* Set extend option value.
44133
*
45134
* @param string $value
46135
* @return $this
136+
* @see https://datatables.net/reference/option/buttons.buttons.extend
47137
*/
48138
public function extend($value)
49139
{
@@ -57,6 +147,7 @@ public function extend($value)
57147
*
58148
* @param string $value
59149
* @return $this
150+
* @see https://editor.datatables.net/reference/button
60151
*/
61152
public function editor($value)
62153
{
@@ -66,8 +157,11 @@ public function editor($value)
66157
}
67158

68159
/**
160+
* Set buttons option value.
161+
*
69162
* @param array $buttons
70163
* @return $this
164+
* @see https://datatables.net/reference/option/buttons.buttons
71165
*/
72166
public function buttons(array $buttons)
73167
{
@@ -134,6 +228,7 @@ public function formTitle($title)
134228
*
135229
* @param string $value
136230
* @return $this
231+
* @see https://datatables.net/reference/option/buttons.buttons.className
137232
*/
138233
public function className($value)
139234
{
@@ -142,6 +237,24 @@ public function className($value)
142237
return $this;
143238
}
144239

240+
/**
241+
* Set destroy option value.
242+
*
243+
* @param string $value
244+
* @return $this
245+
* @see https://datatables.net/reference/option/buttons.buttons.destroy
246+
*/
247+
public function destroy($value)
248+
{
249+
if ($this->isFunction($value)) {
250+
$this->attributes['destroy'] = $value;
251+
} else {
252+
$this->attributes['destroy'] = "function(dt, node, config) { $value }";
253+
}
254+
255+
return $this;
256+
}
257+
145258
/**
146259
* Set customize option value.
147260
*
@@ -178,6 +291,7 @@ public function addClass($class)
178291
*
179292
* @param string $value
180293
* @return $this
294+
* @see https://datatables.net/reference/option/buttons.buttons.text
181295
*/
182296
public function text($value)
183297
{
@@ -186,11 +300,26 @@ public function text($value)
186300
return $this;
187301
}
188302

303+
/**
304+
* Set titleAttr option value.
305+
*
306+
* @param string $value
307+
* @return $this
308+
* @see https://datatables.net/reference/option/buttons.buttons.titleAttr
309+
*/
310+
public function titleAttr($value)
311+
{
312+
$this->attributes['titleAttr'] = $value;
313+
314+
return $this;
315+
}
316+
189317
/**
190318
* Set name option value.
191319
*
192320
* @param string $value
193321
* @return $this
322+
* @see https://datatables.net/reference/option/buttons.buttons.name
194323
*/
195324
public function name($value)
196325
{
@@ -199,6 +328,34 @@ public function name($value)
199328
return $this;
200329
}
201330

331+
/**
332+
* Set namespace option value.
333+
*
334+
* @param string $value
335+
* @return $this
336+
* @see https://datatables.net/reference/option/buttons.buttons.namespace
337+
*/
338+
public function namespace($value)
339+
{
340+
$this->attributes['namespace'] = $value;
341+
342+
return $this;
343+
}
344+
345+
/**
346+
* Set tag option value.
347+
*
348+
* @param string $value
349+
* @return $this
350+
* @see https://datatables.net/reference/option/buttons.buttons.tag
351+
*/
352+
public function tag($value)
353+
{
354+
$this->attributes['tag'] = $value;
355+
356+
return $this;
357+
}
358+
202359
/**
203360
* Set columns option value.
204361
*

0 commit comments

Comments
 (0)