Help

Color code cells depending on response

924 3
cancel
Showing results for 
Search instead for 
Did you mean: 
fabianabbc
4 - Data Explorer
4 - Data Explorer

I'm creating an extension that will create a table and display a response for the user. I want to be able to color some cells depending on the response they get (true/false). Is there a way to do that? Coding? 

3 Replies 3
Maryfletche
4 - Data Explorer
4 - Data Explorer

@fabianabbc wrote:

I'm creating an extension that will create a table and display a response for the user. I want to be able to color some cells depending on the response they get (true/false). Is there a way to do that? Coding?   MetroSurvey


Hello,

To color code cells based on user responses in a table within your extension, you'll need to use HTML and CSS. Use JavaScript to dynamically modify cell styles. Set a class or inline style with appropriate colors based on the response. 

 

 

 

abhibavishi
5 - Automation Enthusiast
5 - Automation Enthusiast

Hey @fabianabbc

I'm not too familiar with your use-case, but here's a script that will do allow you to dynamically set colour codes, assuming the column name is "Response" and the values are "True" or "False":

 

// Get the table
let tableName = "My Table";
let table = base.getTable(tableName);

// Define the "Response" field
let responseField = table.getField("Response");

// Update the options for the "Response" field
await responseField.updateOptionsAsync({
    choices: [
        ...responseField.options.choices.filter((choice) => choice.name !== 'True' && choice.name !== 'False'),
        {name: 'True', color: 'green'},
        {name: 'False', color: 'red'},
    ],
});

// Define the records you want to create
let records = [
    { fields: { 'Response': { name: 'True' } } },
    { fields: { 'Response': { name: 'False' } } },
    { fields: { 'Response': { name: 'True' } } },
];

// Create the records in the table
await table.createRecordsAsync(records);

// Display a response to the user
output.text("Records have been created!");

 

 

Hey! So I tried this code but it seems it's for script. Is that different from an extension code? cuz it's not working for me 😕 and I can't use output in an extension code.