-
I'm currently hitting a wall when trying to create a custom formatter. The column simply appears empty. The header is there, but all the cells below do not contain data. I don't see any errors in the anvil console, so I dont know how to troubleshoot further. My Tabulator component is set to load one of my app_tables. One of the columns in my table is called contact_types. It is a link to another table in which a series of columns are either set to True or None. So for my purposes, it is a dict of keys and values. I want to iterate through that list and for any key with the value of True, add an the name of the key and maybe a little icon. I've tried this numerous ways using a form as the formatter, using a custom formatter that return a RichText item with the content set to a string of HTML code built by the formatter and when those didn't work, I've simplified to returning a string, but still no luck. I have another custom formatter working fine, so I'm truly stumped Here is my custom formatter code:
I create the column in my columns list with this code:
I'd be happy to send a clone link privately, but would rather not post it. Let me know if any other info would be helpful. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
first thing to try is to decorate the function with What is probably happening though is that your formatter is calling the server when doing This causes a Tabulator to receive a Promise object There's some documentation about blocking code and Promises in Anvil in the accessing Javascript section. I have quite an obscure suggestion def custom_getter(row, field):
if field == "content_type":
return dict(row["content_type"])
return row[field]
...
self.tabulator_1.options = {
app_table...
getter: custom_getter
} Why this might work - the getter happens in a place that can suspend and Javascript is expecting a Promise |
Beta Was this translation helpful? Give feedback.
-
fyi - i've added support for throwing Suspension Errors in common 'gotcha' places in tabulator
see #43 |
Beta Was this translation helpful? Give feedback.
first thing to try is to decorate the function with
@anvi.js.report_exceptions
Any errors in python will be reported
What is probably happening though is that your formatter is calling the server when doing
dict(cell.get_value())
This causes a Tabulator to receive a Promise object
But it doesn't know how to handle a Promise object
So it just renders nothing.
It probably doesn't throw an error because Js Tabulator just assumes that's what you intended to do.
Python likes to throw errors, JavaScript avoids it at all costs.
There's some documentation about blocking code and Promises in Anvil in the accessing Javascript section.
search for
blocking code
if you want to learn more.I have quite…