Data Editor
A datagrid editor based on Glide Data Grid
This component is introduced as an alternative to the datatable to support editing the displayed data.
Columns
The columns definition should be a list
of dict
, each dict
describing the associated columns.
Property of a column dict:
title
: The text to display in the header of the column.id
: An id for the column, if not defined, will default to a lower case oftitle
width
: The width of the column.type
: The type of the columns, default to"str"
.
Data
The data
props of rx.data_editor
accept a list
of list
, where each list
represent a row of data to display in the table.
Simple Example
Here is a basic example of using the data_editor representing data with no interaction and no styling. Below we define the columns
and the data
which are taken in by the rx.data_editor
component. When we define the columns
we must define a title
and a type
for each column we create. The columns in the data
must then match the defined type
or errors will be thrown.
Interactive Example
Here we define a State, as shown below, that allows us to print the location of the cell as a heading when we click on it, using the on_cell_clicked
event trigger
. Check out all the other event triggers
that you can use with datatable at the bottom of this page. We also define a group
with a label Data
. This groups all the columns with this group
label under a larger group Data
as seen in the table below.
Cell clicked:
Styling Example
Now let's style our datatable to make it look more aesthetic and easier to use. We must first import DataEditorTheme
and then we can start setting our style props as seen below in dark_theme
.
We then set these themes using theme=DataEditorTheme(**dark_theme)
. On top of the styling we can also set some props
to make some other aesthetic changes to our datatable. We have set the row_height
to equal 50
so that the content is easier to read. We have also made the smooth_scroll_x
and smooth_scroll_y
equal True
so that we can smoothly scroll along the columns and rows. Finally, we added column_select=single
, where column select can take any of the following values none
, single
or multiple
.