From 65c2e6766b37bdc271761d400ea7ab13b11e336e Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Tue, 24 Sep 2024 11:59:31 +0200 Subject: [PATCH] Add editor example --- docs/examples/getting_started/app.py | 1 + pytabulator/tabulator.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/examples/getting_started/app.py b/docs/examples/getting_started/app.py index ecd7287..0d0c268 100644 --- a/docs/examples/getting_started/app.py +++ b/docs/examples/getting_started/app.py @@ -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 diff --git a/pytabulator/tabulator.py b/pytabulator/tabulator.py index 45691a2..2e6165d 100644 --- a/pytabulator/tabulator.py +++ b/pytabulator/tabulator.py @@ -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)