Skip to content

Commit

Permalink
Add editor example
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 24, 2024
1 parent 4adf47f commit 65c2e67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/examples/getting_started/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def tabulator():
.set_options(height=311)
.set_column_formatter_star("Pclass", 3)
.set_column_formatter_tick_cross("Survived", hozAlign="center")
.set_column_editor("Fare", "number", dict(min=0, max=10))
)

@render.code
Expand Down
19 changes: 13 additions & 6 deletions pytabulator/tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,26 @@ def set_column_formatter(
),
)

def set_column_formatter_star(self, column: str, stars: int, **kwargs) -> Self:
def set_column_formatter_star(self, col_name: str, stars: int, **kwargs) -> Self:
formatter_params = dict(stars=stars)
self.set_column_formatter(
column, "star", formatter_params, hozAlign="center", **kwargs
col_name, "star", formatter_params, hozAlign="center", **kwargs
)
return self

def set_column_formatter_tick_cross(self, column, **kwargs) -> Self:
self.set_column_formatter(column, "tickCross", **kwargs)
def set_column_formatter_tick_cross(self, col_name, **kwargs) -> Self:
self.set_column_formatter(col_name, "tickCross", **kwargs)
return self

def set_column_editor(self) -> Self:
return self
def set_column_editor(self, col_name: str, editor: str, editor_params: dict = None, **kwargs: Any) -> Self:
return self.update_column(
col_name,
**dict(
editor=editor,
editorParams=editor_params or dict(),
**kwargs,
),
)

def set_options(self, **kwargs) -> Self:
self._options = self._options.model_copy(update = kwargs)
Expand Down

0 comments on commit 65c2e67

Please sign in to comment.