Hi,
you can do this on client side with JQuery, or, which I prefer, you can use PHP, SQL and CSS:
- In your AppGini project, open Media-tab, [Configure...] the Link, set Behaviour to "No action".
- Follow this tutorial to change the display value: https://bigprof.com/appgini/tips-and-tu ... sing-hooks
Now it's time to figure out what SQL command is needed to get a coloured display of your values.
There are at least two alternatives:
- Let SQL return the desired colours depending on the value
- Let SQL return a specific CSS-class, and colouring (formatting) will be done using CSS.
I prefer the second option, because it gives me more possibilities just by changing CSS without changing PHP or SQL.
Have a look at the following SQL which I'm using in the first step just to figure out how to calculate the required css-class per value according to defined thresholds. There I have a nueric column named
flaeche in a table named
flurstuecke. You will have to use your own tablename and fieldnames.
- chrome_2019-02-01_08-56-02.png (5.18 KiB) Viewed 7584 times
There I have defined thresholds of...
Depending on the value, the SQL statement will return something like this:
- chrome_2019-02-01_08-59-28.png (11.43 KiB) Viewed 7584 times
Once again: The SQL statement above is just to check if my requirements will be met. Open your database workbench (I'm using Adminer or phpMyAdmin) and work on your SQL statement till you get the wanted result. You will have to change the conditions in the
case when ... then ... else ... end-part of the SQL statement.
In the next step, from the SQL select statement we do not need the
SELECT-part, the
FROM-part and the
LIMIT-part. Just take the
CONCAT-part and put it in a $sql variable like this.
Code: Select all
$sql = "concat(
'<span class="',
case
when flaeche < 100 then 'red'
when flaeche < 1000 then 'yellow'
else 'green' end ,
'">',
flaeche,
'</span>'
)
";
Caution This will not work, yet, because we need to escape the double-quotes " by using a backslash-character. So inside the sql-statement, replace all
"-characters by
\".
Your code should look like this now:
Code: Select all
if ($field == '`your_tablename`.`your_fieldname`') {
$sql = "YOUR SQL STATEMENT HERE";
$new_options[$sql] = $caption;
} else if ( ... ) {
// ...
} else {
/* Keep all other fields as-is */
$new_options[$field] = $caption;
}
You will not see any changes, yet, unless you are using your browsers developer tools and inspect the value-elements in your table to verify that they are now placed inside a <span class="..."> tag.
Last step is to create your CSS styles, for example:
Code: Select all
.red { color: red; }
.yellow { /* ... */ }
.green { /* ... */ }
Using this technique, I am able to almost show everything I want. Sometimes it's a bit tricky with the quotes and double quotes between SQL and PHP. Have a look at these examples from one of my projects. I'm using this same technique to render the output in my table views:
- chrome_2019-02-01_09-15-30.png (5.48 KiB) Viewed 7584 times
- chrome_2019-02-01_09-17-46.png (5.05 KiB) Viewed 7584 times
Hope this method will help you in many cases!
Best regards,
Jan
PS: On my "showcase" page,
https://www.bizzworxx.de/en/appgini-improvements/, there is a chapter named
Table view improvements showing a couple of examples.