anvilistas / tabulator

Anvil Wrapper for Tabulator
MIT License
18 stars 5 forks source link

Issue when using Model based tabulator #90

Closed theref closed 1 year ago

theref commented 1 year ago

I'm trying to pass in a list of objects, rather than dicts, to self.tabulator.data. My tabulator config looks like:

self.tabulator.options = {
            "selectable": "highlight",
            "index": "uuid", # or set the index property here
            "use_model": True,
            "getter": "getattr",
        }
        self.tabulator.columns = [
            {"title": "ISIN", "field": "isin"},
            {"title": "SEDOL", "field": "sedol"},
            {"title": "Bloomberg", "field": "bloomberg_code"},
            {"title": "Market Status", "field": "market_status"},

and I can see that self.tabulator.data is set to: [<app.model._instrument.Instrument object>], a list containing one of my own objects.

I'm getting the error:

TypeError: 'str' object is not callable
at app/tabulator/Tabulator/_data_loader.py:82
called from app/tabulator/Tabulator/_data_loader.py:82
called from app/tabulator/Tabulator/_data_loader.py:99
called from app/tabulator/Tabulator/_data_loader.py:108
called from app/tabulator/Tabulator/_data_loader.py:108
called from app/tabulator/Tabulator/_data_loader.py:125
called from app/tabulator/Tabulator/_data_loader.py:273
[An internal error has occurred] - see browser console for more details
TypeError: Cannot read properties of undefined (reading 'then')
    at Ei.load (https://cdn.skypack.dev/-/tabulator-tables@v5.4.0-FoSPNwlYlC9yuj30YIGx/dist=es2020,mode=imports,min/optimized/tabulator-tables.js:17:18560)
    at _._loadInitialData (https://cdn.skypack.dev/-/tabulator-tables@v5.4.0-FoSPNwlYlC9yuj30YIGx/dist=es2020,mode=imports,min/optimized/tabulator-tables.js:17:37989)
    at _._create (https://cdn.skypack.dev/-/tabulator-tables@v5.4.0-FoSPNwlYlC9yuj30YIGx/dist=es2020,mode=imports,min/optimized/tabulator-tables.js:17:36145)
    at https://cdn.skypack.dev/-/tabulator-tables@v5.4.0-FoSPNwlYlC9yuj30YIGx/dist=es2020,mode=imports,min/optimized/tabulator-tables.js:17:34691

@s-cork Have you seen this before?

s-cork commented 1 year ago

The getter should be a function.

just using getattr rather than "getattr" is probably what you want.

theref commented 1 year ago

Immediately worked! Thank you so much