@@ -133,36 +133,6 @@ public function enableFilter(): void
133
133
$ this ->filter = true ;
134
134
}
135
135
136
- //--------------------------------------------------------------------------------------------------------------------
137
- /**
138
- * Returns the HTML code of this table
139
- *
140
- * @param array[] $rows The data shown in the table.
141
- *
142
- * @return string
143
- */
144
- public function getHtmlTable (array $ rows ): string
145
- {
146
- $ this ->prepare ();
147
-
148
- $ ret = $ this ->getHtmlPrefix ();
149
-
150
- $ ret .= Html::generateTag ('table ' , $ this ->attributes );
151
-
152
- $ ret .= $ this ->getHtmlColGroup ();
153
- $ ret .= $ this ->getHtmlHeader ();
154
- $ ret .= $ this ->getHtmlBody ($ rows );
155
- $ ret .= $ this ->getHtmlFooter ();
156
-
157
- $ ret .= '</table> ' ;
158
-
159
- $ ret .= $ this ->getHtmlPostfix ();
160
-
161
- $ this ->generateResponsiveCss ();
162
-
163
- return $ ret ;
164
- }
165
-
166
136
//--------------------------------------------------------------------------------------------------------------------
167
137
/**
168
138
* Returns the total number of columns of this table.
@@ -185,6 +155,30 @@ public function getTitle(): string
185
155
return $ this ->title ;
186
156
}
187
157
158
+ //--------------------------------------------------------------------------------------------------------------------
159
+ /**
160
+ * Returns the HTML code of this table.
161
+ *
162
+ * @param array[] $rows The data shown in the table.
163
+ *
164
+ * @return string
165
+ */
166
+ public function htmlTable (array $ rows ): string
167
+ {
168
+ $ this ->prepare ();
169
+ $ this ->generateResponsiveCss ();
170
+
171
+ $ struct = ['tag ' => 'table ' ,
172
+ 'attr ' => $ this ->attributes ,
173
+ 'inner ' => [['html ' => $ this ->htmlPrefix ()],
174
+ ['html ' => $ this ->htmlColGroup ()],
175
+ ['html ' => $ this ->htmlHeader ()],
176
+ ['html ' => $ this ->htmlBody ($ rows )],
177
+ ['html ' => $ this ->htmlFooter ()]]];
178
+
179
+ return Html::htmlNested ($ struct );
180
+ }
181
+
188
182
//--------------------------------------------------------------------------------------------------------------------
189
183
/**
190
184
* Sets the helper class for generating the table row attributes.
@@ -209,6 +203,17 @@ public function setTitle(string $title): void
209
203
$ this ->title = $ title ;
210
204
}
211
205
206
+ //--------------------------------------------------------------------------------------------------------------------
207
+ /**
208
+ * Returns the HTML code inserted before the HTML code of the table.
209
+ *
210
+ * @return string
211
+ */
212
+ protected function getHtmlPostfix (): string
213
+ {
214
+ return '' ;
215
+ }
216
+
212
217
//--------------------------------------------------------------------------------------------------------------------
213
218
/**
214
219
* Returns the inner HTML code of the body for this table holding the rows as data.
@@ -217,23 +222,29 @@ public function setTitle(string $title): void
217
222
*
218
223
* @return string
219
224
*/
220
- protected function getHtmlBody (array $ rows ): string
225
+ protected function htmlBody (array $ rows ): string
221
226
{
222
- $ ret = Html:: generateTag ( ' tbody ' , [ ' class ' => $ this -> renderWalker -> getClasses ( ' tbody ' )]) ;
223
- $ i = 0 ;
227
+ $ i = 0 ;
228
+ $ htmlRows = '' ;
224
229
foreach ($ rows as $ row )
225
230
{
226
- $ ret .= Html:: generateTag ( ' tr ' , $ this -> tableRow -> getRowAttributes ( $ this -> renderWalker , $ i , $ row )) ;
231
+ $ htmlCells = '' ;
227
232
foreach ($ this ->columns as $ column )
228
233
{
229
- $ ret .= $ column ->getHtmlCell ($ this ->renderWalker , $ row );
234
+ $ htmlCells .= $ column ->htmlCell ($ this ->renderWalker , $ row );
230
235
}
231
- $ ret .= '</tr> ' ;
236
+
237
+ $ htmlRows .= Html::htmlNested (['tag ' => 'tr ' ,
238
+ 'attr ' => $ this ->tableRow ->getRowAttributes ($ this ->renderWalker , $ i , $ row ),
239
+ 'html ' => $ htmlCells ]);
232
240
$ i ++;
233
241
}
234
- $ ret .= '</tbody> ' ;
235
242
236
- return $ ret ;
243
+ $ struct = ['tag ' => 'tbody ' ,
244
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('tbody ' )],
245
+ 'html ' => $ htmlRows ];
246
+
247
+ return Html::htmlNested ($ struct );
237
248
}
238
249
239
250
//--------------------------------------------------------------------------------------------------------------------
@@ -242,7 +253,7 @@ protected function getHtmlBody(array $rows): string
242
253
*
243
254
* @return string
244
255
*/
245
- protected function getHtmlColGroup (): string
256
+ protected function htmlColGroup (): string
246
257
{
247
258
$ ret = '<colgroup> ' ;
248
259
foreach ($ this ->columns as $ column )
@@ -253,7 +264,7 @@ protected function getHtmlColGroup(): string
253
264
$ column ->setSortable (false );
254
265
}
255
266
256
- $ ret .= $ column ->getHtmlCol ();
267
+ $ ret .= $ column ->htmlCol ();
257
268
}
258
269
$ ret .= '</colgroup> ' ;
259
270
@@ -266,7 +277,7 @@ protected function getHtmlColGroup(): string
266
277
*
267
278
* @return string
268
279
*/
269
- protected function getHtmlFooter (): string
280
+ protected function htmlFooter (): string
270
281
{
271
282
return '' ;
272
283
}
@@ -277,13 +288,13 @@ protected function getHtmlFooter(): string
277
288
*
278
289
* @return string
279
290
*/
280
- protected function getHtmlHeader (): string
291
+ protected function htmlHeader (): string
281
292
{
282
- $ ret = Html:: generateTag ( ' thead ' , [ ' class ' => $ this -> renderWalker -> getClasses ( 'thead ' )]);
283
- $ ret .= $ this ->getHtmlInnerHeader ();
284
- $ ret .= ' </thead> ' ;
293
+ $ struct = [ ' tag ' => 'thead ' ,
294
+ ' attr ' => [ ' class ' => $ this ->renderWalker -> getClasses ( ' thead ' )],
295
+ ' html ' => $ this -> htmlInnerHeader ()] ;
285
296
286
- return $ ret ;
297
+ return Html:: htmlNested ( $ struct ) ;
287
298
}
288
299
289
300
//--------------------------------------------------------------------------------------------------------------------
@@ -292,15 +303,15 @@ protected function getHtmlHeader(): string
292
303
*
293
304
* @return string
294
305
*/
295
- protected function getHtmlInnerHeader (): string
306
+ protected function htmlInnerHeader (): string
296
307
{
297
- $ ret = '' ;
308
+ $ struct = [] ;
298
309
if ($ this ->title !==null )
299
310
{
300
311
$ mode = 1 ;
301
312
$ colspan = 0 ;
302
313
303
- $ ret .= Html:: generateTag ( ' tr ' , [ ' class ' => $ this -> renderWalker -> getClasses ( ' title ' )]) ;
314
+ $ inner = [] ;
304
315
foreach ($ this ->columns as $ column )
305
316
{
306
317
$ empty = $ column ->isHeaderEmpty ();
@@ -309,7 +320,9 @@ protected function getHtmlInnerHeader(): string
309
320
{
310
321
if ($ empty )
311
322
{
312
- $ ret .= Html::generateElement ('th ' , ['class ' => $ this ->renderWalker ->getClasses ('empty-header ' )]);
323
+ $ inner [] = ['tag ' => 'th ' ,
324
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('empty-header ' )],
325
+ 'html ' => null ];
313
326
}
314
327
else
315
328
{
@@ -331,70 +344,73 @@ protected function getHtmlInnerHeader(): string
331
344
332
345
if ($ mode ===3 )
333
346
{
334
- if ($ colspan ===1 ) $ colspan = null ;
335
- $ ret .= Html::generateElement ('th ' ,
336
- ['class ' => $ this ->renderWalker ->getClasses ('header ' ),
337
- 'colspan ' => $ colspan ],
338
- $ this ->title );
339
- $ mode = 4 ;
347
+ if ($ colspan ===1 )
348
+ {
349
+ $ colspan = null ;
350
+ }
351
+ $ inner [] = ['tag ' => 'th ' ,
352
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('header ' ),
353
+ 'colspan ' => $ colspan ],
354
+ 'text ' => $ this ->title ];
355
+ $ mode = 4 ;
340
356
}
341
357
342
358
if ($ mode ===4 )
343
359
{
344
- $ ret .= Html::generateElement ('th ' , ['class ' => $ this ->renderWalker ->getClasses ('empty-header ' )]);
360
+ $ inner [] = ['tag ' => 'th ' ,
361
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('empty-header ' )],
362
+ 'html ' => null ];
345
363
}
346
364
}
347
365
348
366
if ($ mode ===2 )
349
367
{
350
- if ($ colspan ===1 ) $ colspan = null ;
351
- $ ret .= Html::generateElement ('th ' ,
352
- ['class ' => $ this ->renderWalker ->getClasses ('header ' ),
353
- 'colspan ' => $ colspan ],
354
- $ this ->title );
368
+ if ($ colspan ===1 )
369
+ {
370
+ $ colspan = null ;
371
+ }
372
+ $ inner [] = ['tag ' => 'th ' ,
373
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('header ' ),
374
+ 'colspan ' => $ colspan ],
375
+ 'text ' => $ this ->title ];
355
376
}
356
377
357
- $ ret .= '</tr> ' ;
378
+ $ struct [] = ['tag ' => 'tr ' ,
379
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('title ' )],
380
+ 'inner ' => $ inner ];
358
381
}
359
382
360
- $ ret .= Html:: generateTag ( ' tr ' , [ ' class ' => $ this -> renderWalker -> getClasses ( ' header-row ' )]) ;
383
+ $ cells = '' ;
361
384
foreach ($ this ->columns as $ column )
362
385
{
363
- $ ret .= $ column ->getHtmlColumnHeader ($ this ->renderWalker );
386
+ $ cells .= $ column ->htmlColumnHeader ($ this ->renderWalker );
364
387
}
365
- $ ret .= '</tr> ' ;
388
+ $ struct [] = ['tag ' => 'tr ' ,
389
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('header-row ' )],
390
+ 'html ' => $ cells ];
366
391
367
392
if ($ this ->filter )
368
393
{
369
- $ ret .= Html:: generateTag ( ' tr ' , [ ' class ' => $ this -> renderWalker -> getClasses ( ' filter-row ' )]) ;
394
+ $ cells = '' ;
370
395
foreach ($ this ->columns as $ column )
371
396
{
372
- $ ret .= $ column ->getHtmlColumnFilter ($ this ->renderWalker );
397
+ $ cells .= $ column ->htmlColumnFilter ($ this ->renderWalker );
373
398
}
374
- $ ret .= '</tr> ' ;
399
+ $ struct [] = ['tag ' => 'tr ' ,
400
+ 'attr ' => ['class ' => $ this ->renderWalker ->getClasses ('filter-row ' )],
401
+ 'html ' => $ cells ];
375
402
}
376
403
377
- return $ ret ;
378
- }
379
-
380
- //--------------------------------------------------------------------------------------------------------------------
381
- /**
382
- * Returns HTML code inserted before the HTML code of the table.
383
- *
384
- * @return string
385
- */
386
- protected function getHtmlPostfix (): string
387
- {
388
- return '' ;
404
+ return Html::htmlNested ($ struct );
389
405
}
390
406
391
407
//--------------------------------------------------------------------------------------------------------------------
392
408
/**
393
- * Returns HTML code appended after the HTML code of the table.
409
+ * Returns the HTML code appended after the HTML code of the table.
394
410
*
395
411
* @return string
396
412
*/
397
- protected function getHtmlPrefix (): string
413
+ protected function htmlPrefix (): string
398
414
{
399
415
return '' ;
400
416
}
0 commit comments