Hi !
We are trying to build a grist plugin/widget to validate data (validata-grist-plugin) , and we want to highlight errors in the table with conditional highlighting.
I wonder what is the best way to perform this.
Right now, given a colId
:
- get the table id (
grist.selectedTable.getTableId()
) - get the column numerical id (i.e. the id from
_grist_Tables_column
internal table) - create an empty rule (
AddEmptyRule
user action) for the specific table and column - fetch the updated
_grist_Tables_column
data, look at the rules to identify the newgristHelper_ConditionalRule
(thanks to the “rules” property) - update two times the
_grist_Tables_column
to add the formula to highlight the right cell (conditional highlighting column) and to add as a widget option the red fill color to highlight the errors (data column)
That’s a lot of steps, and it is error prone. In particular, creating the empty rule and retrieving the created rule happen to be asynchronous, and any other process adding a new rule in between will break the retrieval.
I wonder if I missed an easier / more robust way. Isn’t there a user action where I can already populate the rule with a formula ? Or is there a way I can reliably get the Id of the empty rule created by AddEmptyRule
?