ia\Lib\iaTableIt
Simple echo array to table
| Setup |
De preferencia en header, poner el css
|
<style>
.tableitdiv{overflow-x:auto;border:4px blue double;}
.tableit, .tableit TH, .tableit TD {border: 1px solid silver}
.tableit {border-collapse:collapse;border-spacing:0;margin:auto;overflow-x:hidden;empty-cells:show}
.tableit CAPTION {font-weight:bold;font-size:larger;}
.tableit TH {padding:4px;background-color: whitesmoke}
.tableit TD {padding:4px;vertical-align:top}
.tableit TR:hover {background-color: #f5f5f5}
.tableit TR:nth-child(even) {background-color: #f2f2f2}
.tableit .lft {text-align:left}
.tableit .cen {text-align:center}
.tableit .rgt {text-align:right}
.tableit .date {text-align:center;white-space:pre-line}
.tableit .red {color:red}
.tableit .green{color:darkgreen}
.tableit .blue{color:blue}
.tableit .remark{background-color:yellow}
</style> |
| Usage |
/**
* Simple echo Array to table, keys are column headers
*
* @param array $arr data for table [ ['key1'=>1,'key2'=>'name'], ...]
* @param string $caption
* @param array $header [ 'key'=>['label'=>'', 'class'=>'', 'dec'=>4, 'prefix'=>'$', 'suffix'=>'MN', 'valueClass'=>['Si'=>'red', 'SI'=>'red'] ], ]
* @param boolean $niceHeaders true label($key), false use keys. default true
* @param string $idPrefix sets id for html tags: table id='tableit$idPrefix', tr id='tr$idPrefix$id' default tblIt
* @param string $tableClass sets contining div to class='$tableClassdiv' and table's class='$tableClass'. Default tableit
* @return void
*/
|
| Simple |
$data = [
['item_id'=>12,'item_name'=>'Gato','value_int'=>12,'value_dec'=>12.1345,'ultimo_cambio'=>'2016-01-30','es_camion'=>'No'],
['item_id'=>18,'item_name'=>'Perro azul','value_int'=>-12,'value_dec'=>-12.1345,'ultimo_cambio'=>'2016-01-31','es_camion'=>'Si'],
];
iaTableIt::tableIt($data,"Los datos");
|
Los datos| Item Id | Item Name | Value Int | Value Dec | Último Cambio | Es Camión |
|---|
| 12 | Gato | 12 | 12.12 | 2016-01-30 | No | | 18 | Perro azul | -12 | -12.12 | 2016-01-31 | Si | |
| Specify headers |
$header = [
'es_camion'=>['class'=>'cen', 'valueClass'=>['Si'=>'red']],
'value_dec'=>[ 'label'=>'El Valor','dec'=>3 ],
];
iaTableIt::tableIt($data,"Los datos", $header);
|
Los datos| Item Id | Item Name | Value Int | El Valor | Último Cambio | Es Camión |
|---|
| 12 | Gato | 12 | $12.123 MN | 2016-01-30 | No | | 18 | Perro azul | -12 | $-12.123 MN | 2016-01-31 | Si | |