(Conditional) font color in specific column of Datagrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: (Conditional) font color in specific column of Datagrid
I'm sure i downloaded a stack with modfiedTableField some time ago and was very impressed by what could be done with the tablefield... but ultimately it was a lot of hard work and not practical for me - but that's my mileage.
Keeping in mind the new user: tableField is only simple for experienced users because they are experienced users.
The DG seems scary but is good and holding your hand and guiding you as almost all functionality you may be looking for has been implemented.
The OP had asked how to conditionally colour a cell in a data grid (not the text). Then people posted that we should be considering the tableField "first". For me this doesn't seem like the right tool for the task at hand.
For my own learning i asked if conditional cell (not text) colouring can be done easily for a tableField column, and was answered with vague positive responses of ease and simplicity, which seem dubious to me.
i still hope someone would be kind enough post an example of a tableField where a column will automatically do conditional cell colouring... for comparison if nothing else.
Stam
Keeping in mind the new user: tableField is only simple for experienced users because they are experienced users.
The DG seems scary but is good and holding your hand and guiding you as almost all functionality you may be looking for has been implemented.
The OP had asked how to conditionally colour a cell in a data grid (not the text). Then people posted that we should be considering the tableField "first". For me this doesn't seem like the right tool for the task at hand.
For my own learning i asked if conditional cell (not text) colouring can be done easily for a tableField column, and was answered with vague positive responses of ease and simplicity, which seem dubious to me.
i still hope someone would be kind enough post an example of a tableField where a column will automatically do conditional cell colouring... for comparison if nothing else.
Stam
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: (Conditional) font color in specific column of Datagrid
I suppose one can download all sorts of things, but I'm referring to LC's native field object: Click a few property settings in the Inspector, drop tab-delimited text into it, enjoy.stam wrote: ↑Wed Aug 24, 2022 11:43 pmI'm sure i downloaded a stack with modfiedTableField some time ago and was very impressed by what could be done with the tablefield... but ultimately it was a lot of hard work and not practical for me - but that's my mileage.
Keeping in mind the new user: tableField is only simple for experienced users because they are experienced users.
The DG seems scary but is good and holding your hand and guiding you as almost all functionality you may be looking for has been implemented.
Whether the OP needs anything beyond that remains unknown. May we please let the OP tell us what's needed?
What is the title of this thread, and where is the post from the OP contradicting it?The OP had asked how to conditionally colour a cell in a data grid (not the text).
It wouldn't be the first time I let the most prominent detail override discovering some detailed buried in subsequent posts. In my reading the goal was to color text in ways commonly done in accounting packages and other business tools.
Unless I've missed something already written by redfield, I wonder if we might allow redfield to clarify.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: (Conditional) font color in specific column of Datagrid
Hello everybody,
I have not yet had the time to go deeper into this, only tried a little here and there. Thank you @stam for the example, very impressive but I get it hard to understand those handlers (e. g. LayoutControl). I did copy the code to my Stack but I get an error because the object graphic "colourRect" is not found. And I don't know what the heck those "rects" are for. Does a "rect" represent a table cell
?
I was indeed thinking of using the "simple" table field, but in terms of formatting it doesn't seem much simpler to me.
Then I thought maybe I should create text fields programmatically and build something like a table with them, but the whole thing would not be scrollable, I guess.
The aim is to list stocks and their returns and color the negative returns red and the positive ones green. Either the text or the whole cell - why not if the latter is easier to do. Here's a screenshot:
I have not yet had the time to go deeper into this, only tried a little here and there. Thank you @stam for the example, very impressive but I get it hard to understand those handlers (e. g. LayoutControl). I did copy the code to my Stack but I get an error because the object graphic "colourRect" is not found. And I don't know what the heck those "rects" are for. Does a "rect" represent a table cell

I was indeed thinking of using the "simple" table field, but in terms of formatting it doesn't seem much simpler to me.
Then I thought maybe I should create text fields programmatically and build something like a table with them, but the whole thing would not be scrollable, I guess.
The aim is to list stocks and their returns and color the negative returns red and the positive ones green. Either the text or the whole cell - why not if the latter is easier to do. Here's a screenshot:
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: (Conditional) font color in specific column of Datagrid
There are several ways to do that, some more readable and others faster.
Is that sample representative of the number of lines typically displayed?
What is the he maximum number of lines you can expect?
Is that sample representative of the number of lines typically displayed?
What is the he maximum number of lines you can expect?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: (Conditional) font color in specific column of Datagrid
A regular LC field with tabstops could do that easily, including colored text.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: (Conditional) font color in specific column of Datagrid
Excellent idea.

Now I'm looking forward to hearing back from his to see if it's worth explaining htmlText (which I'd do for long lists) or just setting the text color in place (which would be fast enough if it's just a few lines as shown).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: (Conditional) font color in specific column of Datagrid
Hey @redfield - sorry I should have clarified - the “colourRect” is a rectangular graphic (from the tools palette). I just dropped a rectangular graphic into the column template and named it “colourRect” and made sure the text field was in front of it (to get to this, edit the group of the template that contains all the column templates then select the desired column and edit that group as well). This is resized in LayoutControl and coloured in fillInData.redfield wrote: ↑Mon Aug 29, 2022 10:47 amHello everybody,
I have not yet had the time to go deeper into this, only tried a little here and there. Thank you @stam for the example, very impressive but I get it hard to understand those handlers (e. g. LayoutControl). I did copy the code to my Stack but I get an error because the object graphic "colourRect" is not found. And I don't know what the heck those "rects" are for. Does a "rect" represent a table cell?
LayoutControl gives you the size of a cell in left/top/right/bottom coordinates (the “rect” of the cell), so all that handler does is set the size of the coloured graphic to the size (“rect”) of the cell, and does this for all cells in the column as this is the template for the column. Any resizing of the cell (eg dynamic layouts or even if you just change your mind about dimensions) will trigger this and ensure the colour always fills the cell.
The fillInData is hopefully easier to grasp - if you don’t add code it just adds the the field of the tap-separated text. As this is passed to the handler of this column for each row, it’s an easy place to enter a formula that applies formatting based on the value. In this case a simple conditional if/then/else block to colour the graphic above.
As others have said there are many ways to do this.
“Simpler” ways probably mean (possibly a lot) more code, but whatever suits your needs and appeals to you is the the best way

S.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: (Conditional) font color in specific column of Datagrid
One more question: Do you obtain the data in tab-delimited format? If not, what format is the data in before being displayed?FourthWorld wrote: ↑Mon Aug 29, 2022 4:16 pmThere are several ways to do that, some more readable and others faster.
Is that sample representative of the number of lines typically displayed?
What is the he maximum number of lines you can expect?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: (Conditional) font color in specific column of Datagrid
Theoretically open end, but probably up to 30 the most.

The data comes from a database and I do aFourthWorld wrote: ↑Mon Aug 29, 2022 6:54 pmOne more question: Do you obtain the data in tab-delimited format? If not, what format is the data in before being displayed?
Code: Select all
set linedelimiter to "#"
Thanks @stam for the explanation, I will look into it again.
Re: (Conditional) font color in specific column of Datagrid
No reason you can't with a tableField - LC incudes many functions to work with text, the clickLine and the clickText (check them out in the dictionary). But as mentioned you then need to code the expected behaviours such as highlighting etc.
Probably only if you receive your data as #-delimited text and in that case you'd probably just want to substitute # with a tab, so not sure there is a reason to set the itemDelimiter to # -- but clearly this depends on your data and what you want to do.redfield wrote: ↑Mon Aug 29, 2022 7:42 pmThe data comes from a database and I do aCode: Select all
set linedelimiter to "#"
Most controls expect tab-delimited text in LC (or other than the tableField you can usually use an array as well). In many cases TSV text is fine.
S.
Re: (Conditional) font color in specific column of Datagrid
Yes, the lines can be clickable.
Create a standard LC field with these properties:
Locktext: true
Listbehavior: true
Autohilite: true
Vgrid: true
tabstops: (whatever works, start with 120, you can adjust later)
Get the database data and make it tab-delimited with normal CR line endings.
If you only have a few lines then manipulating the field text itself it a bit easier than managing the htmlText, though htmlText is much faster. For the first method, put the tab-delimited text into the field and then run this handler:
Call the handler by passing the text of the field:
When the user clicks a line, a mouseUp handler in the field should get the clicktext, which will be the text of the whole line. Then you can do something with it.
If you want to try setting the htmlText instead, let us know.
Create a standard LC field with these properties:
Locktext: true
Listbehavior: true
Autohilite: true
Vgrid: true
tabstops: (whatever works, start with 120, you can adjust later)
Get the database data and make it tab-delimited with normal CR line endings.
If you only have a few lines then manipulating the field text itself it a bit easier than managing the htmlText, though htmlText is much faster. For the first method, put the tab-delimited text into the field and then run this handler:
Code: Select all
on parseFld pData
put 1 into tCount
set the itemDel to tab
lock screen
repeat for each line L in pData
if last item of l begins with "-" then
set the textcolor of last item of line tCount of fld 1 to "red"
else
set the textcolor of last item of line tCount of fld 1 to "green"
end if
add 1 to tCount
end repeat
unlock screen
end parseFld
Code: Select all
parseFld the text of fld 1
If you want to try setting the htmlText instead, let us know.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com