Skip to content

Commit

Permalink
Merge pull request #123 from s-cork/designer-support
Browse files Browse the repository at this point in the history
support designer
  • Loading branch information
s-cork authored Sep 29, 2023
2 parents d46e98e + 3c8fd51 commit 2043078
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions client_code/Tabulator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@

from ._data_loader import Query

try:
from anvil.designer import in_designer
except ImportError:
in_designer = False

if in_designer:
from anvil.js.window import document

_s = document.createElement("style")
_s.textContent = """
.tabulator-row .tabulator-cell {
font-style: italic;
}"""
document.head.append(_s)


class Tabulator(TabulatorTemplate):
theme = _default_theme
Expand Down Expand Up @@ -97,6 +112,21 @@ def _initialize(self):
options = _camelKeys(self._options) | _camelKeys(self.options)
options["columns"] = [_camelKeys(defn) for defn in options["columns"]]
options["columnDefaults"] = _camelKeys(options["columnDefaults"])
if in_designer and type(self) is Tabulator:
pagination = options.get("pagination")
data = [
{
"columnA": "columnA",
"columnB": "columnB",
"columnC": "columnC",
"columnD": "columnD",
}
] * 2
if pagination:
data *= 3
options["paginationSize"] = 2
options["data"] = data
options["autoColumns"] = True

# if we're using the rowSelection make sure things are selectable
if (
Expand Down Expand Up @@ -266,6 +296,19 @@ def get_page(self):
def set_page(self, page):
"""set the current page"""

def _anvil_set_property_values_(self, updates):
re_init = False
for attr, value in updates.items():
if attr in self._options:
self._options[attr] = value
re_init = True
else:
setattr(self, attr, value)

if re_init and self._t:
self._t.destroy()
self._initialize()


for method in _methods:
delattr(Tabulator, method)

0 comments on commit 2043078

Please sign in to comment.