question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to stylize individual cells in a vscode-data-grid

See original GitHub issue

Describe the bug

I’m attempting to stylize individual cells in a vscode-data-grid, however the text is being HTML escaped. Is it possible to set a cell to stylized HTML? Or to go back and set the CSS of a cell once the cell has been created?

To reproduce

I’m creating a grid ala:

                  <vscode-data-grid
                    class='my-data-grid'
                    grid-template-columns='240px 320px 200px 200px'
                  >
                  </vscode-data-grid>

…and then setting the data like so:

                  const myDataGrid = document.querySelector('.my-data-grid');
                  myDataGrid.columnDefinitions = [
                    { columnDataKey: 'columnKey0', title: 'A' },
                    { columnDataKey: 'columnKey1', title: 'B' },
                    { columnDataKey: 'columnKey2', title: 'C' },
                    { columnDataKey: 'columnKey3', title: 'D' }
                  ];

                  const myRowsData = [];
                  myData.forEach(data => {
                    const connectedStatus = (data.connectedStatus === 'Connected')
                      ? '<span style="green">Connected</span>'
                      : '<span style="red">Not Connected</span>';
                    nonScratchOrgsRowsData.push({
                      columnKey0: data.a,
                      columnKey1: data.b,
                      columnKey2: data.c,
                      columnKey3: connectedStatus
                    });
                  });
                  myDataGrid.rowsData = myRowsData;

Expected behavior

I’d like the text in column 3 to be stylized.

Current behavior

The HTML (the spans) are not stylized and instead of Connected appearing, <span style="green">Connected</span> appears.

Additional context

I tried to keep this issue short & sweet. If you need any more info on this issue, just let me know.

Also, I didn’t see anything in the vscode-data-grid README (https://github.com/microsoft/vscode-webview-ui-toolkit/blob/main/src/data-grid/README.md) on styling, and I didn’t notice a means to edit the styling in the interactive story book either (https://microsoft.github.io/vscode-webview-ui-toolkit/?path=/story/library-data-grid--default&args=gridTemplateColumns:foo;hasCustomTitles:true).

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffb-sfdccommented, Jul 25, 2022

I think we’re good, thanks @hawkticehurst

1reaction
jeffb-sfdccommented, Jun 21, 2022

I should also mention that I set a break point, and after

myDataGrid.rowsData = myRowsData;

…is called, I tried to manually set the color, like so:

myDataGrid.rowsData[0].columnKey3.fontcolor = "red"
myDataGrid.rowsData[1].columnKey3.fontcolor = "#FF0000"
myDataGrid.rowsData[2].columnKey3.fontcolor = "FF0000"

…but none of these set the color to red

Read more comments on GitHub >

github_iconTop Results From Across the Web

vscode-webview-ui-toolkit/README.md at main - data-grid
Place data grids in a main content area to display as much information as possible in one view. It's ok to use a...
Read more >
User and Workspace Settings - Visual Studio Code
Another way to customize your editor by language is by running the global command Preferences: Configure Language Specific Settings (command ID: workbench.
Read more >
Three ways to style React Data Grid with Custom CSS Styles
Open this directory with your code editor. If you do, you can move on to applying custom styling.
Read more >
DataGridView Class (System.Windows.Forms) | Microsoft Learn
How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView ... to the cells in the DataGridView if no other cell...
Read more >
Editing in Blazor DataGrid Component | Syncfusion
The Editing functionalities can be performed based on the primary key value of the selected row. If PrimaryKey is not defined in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found