Table::html($data, $tableInfo = false);
$data
- the array itself to be printed$tableInfo()
- an array of table settings$data
array has the following structure: Array ( [0] => Array // 1 ( [0] => Cell_00 // 1 1 [1] => Cell_01 // 2 1 [2] => Cell_02 // 3 1 ) [1] => Array // 2 ( [0] => Cell_10 // 1 [1] => Cell_11 // 2 [2] => Cell_12 // 3 ) );
for($i=0;$i<5;$i++) for($j=0;$j<5;$j++) $matrix[$i][$j] = $i.$j;
rowspan
and data grouping. Array ( [0] => Array ( [0] => Cell_00 [1] => Cell_01 [2] => Cell_02 ) [1] => Array ( [0] => Cell_10 [1] => Cell_11 [2] => Array ( [0] => Array ( [0] => Cell_120 ) [1] => Array ( [0] => Cell_121 ) ) ) )
Array ( [0] => Array ( [0] => Cell_00 [1] => Cell_01 [2] => Cell_02 ) [1] => Array ( [0] => Cell_10 [1] => Array ( [0] => Array ( [0] => Cell_110 [1] => Array ( [0] => Array ( [0] => Cell_1100 ) [1] => Array ( [0] => Cell_1101 ) ) ) [1] => Array ( [0] => Cell_111 [1] => Cell_112 ) ) ) )
rowspan'
. We now turn to manual table setup.$data
array may contain a subarray ['tableInfo']
- in it you can specify various settings, depending on its ( 'tableInfo'
) location. Array ( [0] => Array(...) [1] => Array(...) ... [n] => Array(...) [tableInfo] => Array (...) )
'tableInfo'
located in the root of the array allows you to set general settings and parameters for the entire table: Array ( [rowspan] => false // . . [cols] => Array // ( [0] => Array ( [title] => //title ( th). [key] => name //key . ) [1] => Array //title key ( // cols title, key [title] => // , , [key] => tel // ) ) // HTML : [id] => tableId [class] => tableClass [style] => color:#000; [args] => align=left width=80% // args , . )
Table::html($data, $tableInfo = false);
isset($data['tableInfo'] && isset($tableInfo)
), then in controversial cases, priority is given to the rules from the second $tableInfo
. array_replace_recursive($data['tableInfo'], $tableInfo);
title
Array ( [0] => Array ( [0] => Cell_00 [1] => Cell_01 [2] => Cell_02 ) [1] => Array ( [0] => Cell_10 [1] => Cell_11 [2] => Cell_12 ) [tableInfo] => Array ( [cols] => Array ( [0] => Array ( [title] => Title 1 ) [1] => Array ( [title] => Title 2 ) [2] => Array ( [title] => Title 3 ) ) ) )
key
usage example Array ( [0] => Array ( [0] => Cell_00 [1] => Cell_01 [2] => Cell_02 ) [1] => Array ( [0] => Cell_10 [1] => Cell_11 [2] => Cell_12 [3] => Cell_13 // , .. key ) [tableInfo] => Array ( [cols] => Array ( [0] => Array ( [key] => 2 ) [1] => Array ( [key] => 0 ) [2] => Array ( [key] => 1 ) ) ) )
$exmpl3 = array( 'tableInfo' => array( 'cols' => array( 0 => array('key' => 'cell0'), 1 => array('key' => 'cell1'), 2 => array('key' => 'cell2'), ) ), 0 => array( 'cell0' => 'Cell_00', 'cell2' => 'Cell_02', 'cell1' => 'Cell_01', ), 1 => array( 'cell0' => 'Cell_10', 'sub' => array( 0 => array( 'cell1' => 'Cell_110', 'sub' => array( 0 => array( 'cell2' => 'Cell_1100', ), 1 => array( 'cell0' => 'asdasd_10', // , .. 'cell1' => 'asdasd_110',// 'cell2' => 'Cell_1101' ) ) ), 'sub' => array('cell1' => 'Cell_111', 'cell2' => 'Cell_112'), ) ) );
key
is not used at all, then the array of output keys is populated with all keys of cells (not subarrays) that are in this line. For example in this case: $exmpl = array( 0 => array( 0 => 'Cell_00', 1 => 'Cell_01', 2 => 'Cell_02', ), 1 => array( 0 => 'Cell_10', 1 => 'Cell_11', 2 => 'Cell_12', ), );
$colKeys ( )
will look like this: $colKeys = array(0, 1, 2);
Array ( [0] => Array( [qwe] => [asd] => [tableInfo] => Array (...) ) [1] => Array(...) ... )
Array ( [0] => Array( [qwe] => [asd] => [zxc] => Array( [0] => Array( [jkl] => [tableInfo] => Array (...) ) [1] => Array() ) ) [1] => Array(...) ... )
'tableInfo'
located in the array of cells may contain settings for the row in which it is located and / or settings for each individual cell: 'tableInfo' => array( 'rowspan' => false, // rowspan 'rowspan' => true, // rowspan 'rowspan' => 5, // rowspan 'keys' => array( // 'delete' => 'all', // 'delete' => array('cell2'), // ( 'cell2') 'add' => array('cell3'), // ( 'cell3') 'forwarding' => array( // . 0 => array( 'src' => 'cell1', // cell1 'dst' => 'cell2' // cell2 ), ), // , ), //.. 'cells' => array( // 'cell2' => array( // 'cell2' 'rowspan' => false, // 'rowspan' => true, // 'rowspan' => 5, // 'colspan' => 6, // // HTML : 'id' => 'cellId', 'class' => 'cellClass', 'style' => 'color:#000;', 'args' => 'align=left width=80%' ) ), // HTML : 'id' => 'rowId', 'class' => 'rowClass', 'style' => 'color:#000;', 'args' => 'align=left width=80%' );
Source: https://habr.com/ru/post/253207/
All Articles