Skip to content

Instantly share code, notes, and snippets.

@Jmos
Created October 5, 2019 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jmos/5f44cadb9c91e9d715d9ef74d2cfeca5 to your computer and use it in GitHub Desktop.
Save Jmos/5f44cadb9c91e9d715d9ef74d2cfeca5 to your computer and use it in GitHub Desktop.
Atk table color by dependent value
<?php
require '../vendor/autoload.php';
use atk4\ui\App;
$app = new App();
$app->initLayout('Centered');
$test_data = [
['name'=>'record1','value'=>'100','datum_field'=>new DateTime('2019-09-29')],
['name'=>'record2','value'=>'200','datum_field'=>new DateTime('2019-09-28')],
['name'=>'record3','value'=>'300','datum_field'=>new DateTime('2019-09-30')],
['name'=>'record4','value'=>'400','datum_field'=>new DateTime('2019-10-01')],
];
$table = $app->add('Table');
$table->setSource($test_data);
$table->addHook('beforeRow',function($table){
if ($table->current_row['value']==100){
$table->t_row->template[0] = "\n <tr class=\"red\" data-id=\"";
}elseif ($table->current_row['value']==200){
$table->t_row->template[0] = "\n <tr class=\"green\" data-id=\"";
}else{
$table->t_row->template[0] = "\n <tr data-id=\"";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment