Displaying HTML in DataGrid (table mode) – supported or not?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Displaying HTML in DataGrid (table mode) – supported or not?
Hello,
I’m working with a DataGrid in table mode (not form) in LiveCode.
I would like to display formatted text (HTML), for example something like:
<b>Black</b> <font color="red">Red</font> <b>Black</b>
or more concretely (bridge application):
5 ♥ E+2 where only the ♥ symbol is red.
I have tried several approaches:
set the dgText of group "dgTest" to ...
set the dgData of group "dgTest" to ...
using "htmlText" in the array
setting properties like dgProp["htmlText"] or similar
In all cases, the HTML is either displayed as plain text or ignored.
Question:
Is it actually possible to display HTML-formatted text (with partial colors) inside a DataGrid cell in table mode?
If not:
is there a recommended workaround?
or is switching to a form-style DataGrid / custom template the only solution?
Any clarification on what is officially supported would be very helpful.
Thanks in advance!
I’m working with a DataGrid in table mode (not form) in LiveCode.
I would like to display formatted text (HTML), for example something like:
<b>Black</b> <font color="red">Red</font> <b>Black</b>
or more concretely (bridge application):
5 ♥ E+2 where only the ♥ symbol is red.
I have tried several approaches:
set the dgText of group "dgTest" to ...
set the dgData of group "dgTest" to ...
using "htmlText" in the array
setting properties like dgProp["htmlText"] or similar
In all cases, the HTML is either displayed as plain text or ignored.
Question:
Is it actually possible to display HTML-formatted text (with partial colors) inside a DataGrid cell in table mode?
If not:
is there a recommended workaround?
or is switching to a form-style DataGrid / custom template the only solution?
Any clarification on what is officially supported would be very helpful.
Thanks in advance!
-
Emily-Elizabeth
- Posts: 195
- Joined: Mon Jan 03, 2022 7:10 pm
- Contact:
Re: Displaying HTML in DataGrid (table mode) – supported or not?
Doesn't look like you can't set the htmlText, perhaps it's something that can be added.
-
richmond62
- Livecode Opensource Backer

- Posts: 10397
- Joined: Fri Feb 19, 2010 10:17 am
Re: Displaying HTML in DataGrid (table mode) – supported or not?
Looks logically wonky: surely:Doesn't look like you can't set the htmlText, perhaps it's something that can be added.
"Doesn't look like you can set the htmlText, perhaps it's something that can be added."
-
bamakojeff
- Posts: 37
- Joined: Tue Dec 06, 2022 6:53 pm
Re: Displaying HTML in DataGrid (table mode) – supported or not?
I do not believe that you can do this in Table mode for a DataGrid. But you can definitely do it in Form mode. Since you put "normal" livecode fields into a form, in your datagrid script to populate the form, you can assign the htmltext of the field just like you can any livecode field.
So if the field in the form was called "bridgeFld", you create an array to hold the data:
Then in the script for the datagrid you would write:
And your line in the DataGrid would look like
5 ♥ E+2
(This assumes that the "foregroundColor" of the field is black. But you could set it to whatever you wanted. Or you could specify all the colors in the HTML text as well if you wished.)
DataGrids are "deep magic" but the basics are not difficult. I've attached a stack which does this if it helps give you ideas.
HTH
Jeff
So if the field in the form was called "bridgeFld", you create an array to hold the data:
Code: Select all
put "5 <font color='#FF0000'>♥</font> E+2" into tDataArray[1]["bid"]
set the dgData of group "myDataGrid" to tDataArrayCode: Select all
on FillInData pDataArray
set the htmltext of fld "bridgeFld" of me to pDataArray["bid"]
end FillInData5 ♥ E+2
(This assumes that the "foregroundColor" of the field is black. But you could set it to whatever you wanted. Or you could specify all the colors in the HTML text as well if you wished.)
DataGrids are "deep magic" but the basics are not difficult. I've attached a stack which does this if it helps give you ideas.
HTH
Jeff
- Attachments
-
- BridgeNotes.livecode.zip
- (5.41 KiB) Downloaded 6 times
Re: Displaying HTML in DataGrid (table mode) – supported or not?
Thanks Jeff,
That confirms exactly what I was observing.
I initially tried to do this in table mode, but HTML is clearly not supported there (it is either ignored or displayed as plain text). Your explanation about using form mode with real fields makes things much clearer.
In my case (bridge scoring), I specifically wanted to display things like:
5 ♥ E+2 with only the ♥ in red.
I managed to get an acceptable result in table mode using Unicode symbols, but without partial coloring. So for now I’ll probably keep that approach for performance and simplicity.
However, your example with htmlText in a form DataGrid is very helpful, and I may switch to that if I decide to prioritize richer rendering.
Thanks also for the sample stack — much appreciated!
Best regards
That confirms exactly what I was observing.
I initially tried to do this in table mode, but HTML is clearly not supported there (it is either ignored or displayed as plain text). Your explanation about using form mode with real fields makes things much clearer.
In my case (bridge scoring), I specifically wanted to display things like:
5 ♥ E+2 with only the ♥ in red.
I managed to get an acceptable result in table mode using Unicode symbols, but without partial coloring. So for now I’ll probably keep that approach for performance and simplicity.
However, your example with htmlText in a form DataGrid is very helpful, and I may switch to that if I decide to prioritize richer rendering.
Thanks also for the sample stack — much appreciated!
Best regards