FoxPro Programming
htmlDataGrid: Adding color code next to the numbers
Gravatar is a globally recognized avatar based on your email address. htmlDataGrid: Adding color code next to the numbers
  Kathy
  All
  Sep 22, 2023 @ 08:24am

Hello there,
my apology if this is and old question.
This is about htmlDataGrid column configuration and I need to add color codes right next to the numbers in each row, it can be a colored box/circle, etc., so something like this one below:
I'm trying to ignore sending them in a separate column because they need to be next to the numbers and cannot float in responsive mode and I'm not sure if it's a good idea to define a fixed width for their column so I was thinking I might be able to add a small html tag right beside the content of the column in column configuration, something like an SVG tag, etc., and then send the color through a table driven variable from Fox.

I would appreciate any suggestion.
Kathy

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Rick Strahl
  Kathy
  Sep 22, 2023 @ 08:59am

You can probably use a FontAwesome icon and adjust the font size and color to fit.

<i class="fas fa-square" style="font-size: 25pt ; color: red"></i> Some Text

which produces:


Some Text


You might have to adjust the font-awesome styling above depending on the version of FontAwesome that you're using.

You can probably do this without fonts too just using a span with some padding:

<span style="padding: 0.5em 1.25em; background: firebrick"></span>   Some Text

which looks like this:


  Some Text


Whatever you come up with for the styling, dump it into a CSS class (.square-box { }) so you can easily adjust the size of the box or font in one place.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Kathy
  Rick Strahl
  Sep 22, 2023 @ 07:29pm

Thank you so much Rick,
your note was as helpful as always.
I did it like this and it looks like to be working for now but they are for the Title field which is character:

loColumn_1 = loGridConfig.ADDCOLUMN(['<i class="fas fa-square" style="font-size: 15pt ; color: ' + color + '"></i>' + title],"","C")

And I think it will also work for sortable numeric fields with no conflict, I just did a quick test and it worked but please correct me if I'm wrong.

Thanks again,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Rick Strahl
  Kathy
  Sep 23, 2023 @ 05:22pm

Yes this would also work with a number field but you'd have to parse the number into a string as part of the value you're displaying. Ideally you'd have to pre-sort the list before displaying because numbers won't sort right using string values unless you pad.

Frankly though, when you build complex grids like this, a lot of times it's cleaner and easier to just build it by hand using a <% SCAN %> loop in the mark up, but you'd lose the ability to sort.

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Kathy
  Rick Strahl
  Sep 26, 2023 @ 07:55am

Thank you so much Rick,
I'm going to use this grid on kind of a dashboard page with other grids and charts, so wish me luck with sorting, etc. 😃
I'll keep your notes as my reference.
Thanks again,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Rick Strahl
  Kathy
  Sep 26, 2023 @ 08:26am

using HtmlDataGrid works well enough, it's sometimes just difficult to get the nested string expressions right.

HotReload helps 😄 as you can make changes quickly and recover quickly from bad syntax.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Kathy
  Rick Strahl
  Sep 29, 2023 @ 05:41am

Thanks for the note Rick.
And would you please explain what you mean by "HotReload"! Is it a function/tool or is it an expression? 😃
Thanks,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: htmlDataGrid: Adding color code next to the numbers
  Kathy
  Rick Strahl
  Oct 5, 2023 @ 07:51am

This is SO cool.
Thank you so much Rick.
Kathy

© 1996-2025