Aug 10, 2023 12:00 PM
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?
Aug 14, 2023 04:11 AM - edited Aug 15, 2023 09:36 PM
@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.
Aug 14, 2023 05:13 AM - edited Aug 14, 2023 05:14 AM
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!");
Sep 05, 2023 06:42 AM
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.