1212 */
1313trait Select
1414{
15- /**
16- * Set select option value.
17- *
18- * @param bool|array $value
19- * @return $this
20- * @see https://datatables.net/reference/option/select
21- */
22- public function select (bool |array $ value = true ): static
23- {
24- $ this ->attributes ['select ' ] = $ value ;
25-
26- return $ this ;
27- }
28-
2915 /**
3016 * Set select blurable option value.
3117 *
@@ -35,9 +21,7 @@ public function select(bool|array $value = true): static
3521 */
3622 public function selectBlurable (bool $ value = true ): static
3723 {
38- $ this ->attributes ['select ' ]['blurable ' ] = $ value ;
39-
40- return $ this ;
24+ return $ this ->select (['blurable ' => $ value ]);
4125 }
4226
4327 /**
@@ -49,9 +33,7 @@ public function selectBlurable(bool $value = true): static
4933 */
5034 public function selectClassName (string $ value = 'selected ' ): static
5135 {
52- $ this ->attributes ['select ' ]['className ' ] = $ value ;
53-
54- return $ this ;
36+ return $ this ->select (['className ' => $ value ]);
5537 }
5638
5739 /**
@@ -80,9 +62,7 @@ public function selectAddClassName(string $class): static
8062 */
8163 public function selectInfo (bool $ value = true ): static
8264 {
83- $ this ->attributes ['select ' ]['info ' ] = $ value ;
84-
85- return $ this ;
65+ return $ this ->select (['info ' => $ value ]);
8666 }
8767
8868 /**
@@ -94,9 +74,7 @@ public function selectInfo(bool $value = true): static
9474 */
9575 public function selectItems (string $ value = 'row ' ): static
9676 {
97- $ this ->attributes ['select ' ]['items ' ] = $ value ;
98-
99- return $ this ;
77+ return $ this ->select (['items ' => $ value ]);
10078 }
10179
10280 /**
@@ -107,9 +85,7 @@ public function selectItems(string $value = 'row'): static
10785 */
10886 public function selectItemsRow (): static
10987 {
110- $ this ->attributes ['select ' ]['items ' ] = Builder::SELECT_ITEMS_ROW ;
111-
112- return $ this ;
88+ return $ this ->select (['items ' => Builder::SELECT_ITEMS_ROW ]);
11389 }
11490
11591 /**
@@ -120,9 +96,7 @@ public function selectItemsRow(): static
12096 */
12197 public function selectItemsColumn (): static
12298 {
123- $ this ->attributes ['select ' ]['items ' ] = Builder::SELECT_ITEMS_COLUMN ;
124-
125- return $ this ;
99+ return $ this ->select (['items ' => Builder::SELECT_ITEMS_COLUMN ]);
126100 }
127101
128102 /**
@@ -133,9 +107,7 @@ public function selectItemsColumn(): static
133107 */
134108 public function selectItemsCell (): static
135109 {
136- $ this ->attributes ['select ' ]['items ' ] = Builder::SELECT_ITEMS_CELL ;
137-
138- return $ this ;
110+ return $ this ->select (['items ' => Builder::SELECT_ITEMS_CELL ]);
139111 }
140112
141113 /**
@@ -147,9 +119,7 @@ public function selectItemsCell(): static
147119 */
148120 public function selectSelector (string $ value = 'td ' ): static
149121 {
150- $ this ->attributes ['select ' ]['selector ' ] = $ value ;
151-
152- return $ this ;
122+ return $ this ->select (['selector ' => $ value ]);
153123 }
154124
155125 /**
@@ -161,9 +131,7 @@ public function selectSelector(string $value = 'td'): static
161131 */
162132 public function selectStyle (string $ value = 'os ' ): static
163133 {
164- $ this ->attributes ['select ' ]['style ' ] = $ value ;
165-
166- return $ this ;
134+ return $ this ->select (['style ' => $ value ]);
167135 }
168136
169137 /**
@@ -174,9 +142,7 @@ public function selectStyle(string $value = 'os'): static
174142 */
175143 public function selectStyleApi (): static
176144 {
177- $ this ->attributes ['select ' ]['style ' ] = Builder::SELECT_STYLE_API ;
178-
179- return $ this ;
145+ return $ this ->select (['style ' => Builder::SELECT_STYLE_API ]);
180146 }
181147
182148 /**
@@ -187,7 +153,23 @@ public function selectStyleApi(): static
187153 */
188154 public function selectStyleSingle (): static
189155 {
190- $ this ->attributes ['select ' ]['style ' ] = Builder::SELECT_STYLE_SINGLE ;
156+ return $ this ->select (['style ' => Builder::SELECT_STYLE_SINGLE ]);
157+ }
158+
159+ /**
160+ * Set select option value.
161+ *
162+ * @param bool|array $value
163+ * @return $this
164+ * @see https://datatables.net/reference/option/select
165+ */
166+ public function select (bool |array $ value = true ): static
167+ {
168+ if (is_array ($ value )) {
169+ $ this ->attributes ['select ' ] = array_merge ((array ) $ this ->attributes ['select ' ], $ value );
170+ } else {
171+ $ this ->attributes ['select ' ] = $ value ;
172+ }
191173
192174 return $ this ;
193175 }
@@ -200,9 +182,7 @@ public function selectStyleSingle(): static
200182 */
201183 public function selectStyleMulti (): static
202184 {
203- $ this ->attributes ['select ' ]['style ' ] = Builder::SELECT_STYLE_MULTI ;
204-
205- return $ this ;
185+ return $ this ->select (['style ' => Builder::SELECT_STYLE_MULTI ]);
206186 }
207187
208188 /**
@@ -213,9 +193,7 @@ public function selectStyleMulti(): static
213193 */
214194 public function selectStyleOS (): static
215195 {
216- $ this ->attributes ['select ' ]['style ' ] = Builder::SELECT_STYLE_OS ;
217-
218- return $ this ;
196+ return $ this ->select (['style ' => Builder::SELECT_STYLE_OS ]);
219197 }
220198
221199 /**
@@ -226,8 +204,19 @@ public function selectStyleOS(): static
226204 */
227205 public function selectStyleMultiShift (): static
228206 {
229- $ this ->attributes ['select ' ]['style ' ] = Builder::SELECT_STYLE_MULTI_SHIFT ;
207+ return $ this ->select (['style ' => Builder::SELECT_STYLE_MULTI_SHIFT ]);
208+ }
230209
231- return $ this ;
210+ /**
211+ * @param string|null $key
212+ * @return mixed
213+ */
214+ public function getSelect (string $ key = null ): mixed
215+ {
216+ if (is_null ($ key )) {
217+ return $ this ->attributes ['select ' ] ?? true ;
218+ }
219+
220+ return $ this ->attributes ['select ' ][$ key ] ?? false ;
232221 }
233222}
0 commit comments