Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add column resize for data editor #2099

Merged
merged 1 commit into from Nov 2, 2023
Merged

Conversation

Lendemor
Copy link
Collaborator

Allow resizing columns with onColumnResize.

How it works:

data_ = {
    "Column1": [1, 2, 3, 4, 5],
    "Column2": ["A", "B", "C", "D", "E"],
    "Column3": [0.1, 0.2, 0.3, 0.4, 0.5],
}

class State(rx.State):
    columns: list = [
        {"title": "Column1", "id": "column1", "type": "int"},
        {"title": "Column2", "id": "column2", "type": "str"},
        {"title": "Column3", "id": "column3", "type": "float"},
    ]
    data: list = [
        dict((key.lower(), value) for key, value in zip(data_.keys(), values))
        for values in zip(*data_.values())
    ]

    def col_resized(self, column, width):
        print(column, width)
        for col in self.columns:
            if col.get("id") == column.get("id"):
                col["width"] = width


def index():
    return rx.hstack(
        # rx.foreach(["B1", "B2", "B3"], button_stop),
        # on_click=State.outer_click,
        rx.data_editor(
            columns=State.columns,
            data=State.data,
            rows=5,
            on_column_resize=State.col_resized,
            overscroll_x=100,
        )
    )

@Lendemor
Copy link
Collaborator Author

Lendemor commented Nov 2, 2023

Need reflex-dev/reflex-web#292

@picklelo picklelo merged commit eeeab44 into main Nov 2, 2023
37 checks passed
@masenf masenf deleted the lendemor/dateditor_resize_columns branch December 6, 2023 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants