-
Notifications
You must be signed in to change notification settings - Fork 193
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
data table tutorial #304
data table tutorial #304
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conversational tone is a little bit too much for me throughout the tutorial. I think it's great to have a some, to make the reader feel they are part of something, but reading through, i need less "we" and "our" and more "the component ...", "this event handler ...", "the state defines a var, ...", etc.
This would break up the conversational tone with more precise language, without making the whole thing read like reference material.
Adding type hints on all event handlers would help the code examples stand on their own.
|
||
|
||
|
||
# Data Table Tutorial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this isn't for the rx.data_table
component, maybe the heading should be "Data Editor Tutorial"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is something I discussed with nikhil, it is just that more commonly people refer to this component as a data table. Perhaps we could call it the data table (editable).
1. title: The text to display in the header of the column | ||
2. id: An id for the column, if not defined, will default to a lower case of title | ||
3. width: The width of the column | ||
4. type: The type of the columns, default to "str" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use code marks on the key names
1. title: The text to display in the header of the column | |
2. id: An id for the column, if not defined, will default to a lower case of title | |
3. width: The width of the column | |
4. type: The type of the columns, default to "str" | |
1. `title`: The text to display in the header of the column | |
2. `id`: An id for the column, if not defined, will default to a lower case of title | |
3. `width`: The width of the column (in pixels?) | |
4. `type`: The type of the columns, default to "str" |
For type
, how can i find out what types are available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there more recognized keys for a column dict as well? where are those defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I can tell these are the only 4, but going through the reflex docs and the reflex code these are not actually defined anywhere that I can see so it is hard to say if there are more, we will need to chat to Thomas and ask
|
||
There are several other event triggers that are worth exploring. The `on_item_hovered` event trigger is called whenever the user hovers over an item in the datatable. The `on_delete` event trigger is called when the user deletes a cell from the datatable. | ||
|
||
The final event trigger to check out is `on_column_resize`, this allows us to manually resize the width of our columns by hand. The event trigger returns the `col` we are adjusting and the new `width` we have defined. We then index into `self.cols` defined in our state and change the `width` of that column using this code: `self.cols[col['pos']]['width'] = width`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows us to manually resize the width of our columns by hand
This sounds sort of funny to me.
Maybe something more like, "on_column_resize allows us to respond to the user dragging the handle between columns"
I think more description of the col
arg is warranted, since it appears to be a dictionary, but not clear what is inside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added both of these
By default there is a `vertical_border` between the columns, we can turn it off by setting this prop to `False`. We can define how many columns a user can select at a time by setting the `column_select` prop. It can take values of `"none", "single", "multi"`. | ||
|
||
We can allow `overscroll_x`, which allows users to scroll past the limit of the actual horizontal content. There is an equivalent `overscroll_y`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest directly linking to the component docs where all of these props (and more) are displayed in table form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
|
||
Lastly let's add in an API so we can live stream data into our datatable. | ||
|
||
Here we use a [Background Task](https://reflex.dev/docs/advanced-guide/background-tasks) to stream the data into the table without blocking UI interactivity. We call an advice API using `httpx` and then append that data to the `self.table_data` state var. We also create a button that allows us to start and pause the streaming of the data by changing the value of the boolean state var `running` using the event handler `toggle_pause`. If the `running` state var is set to `True` we stream the API data, when it is set to `False` we break out of the `while` loop and end the background event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we use a [Background Task](https://reflex.dev/docs/advanced-guide/background-tasks) to stream the data into the table without blocking UI interactivity. We call an advice API using `httpx` and then append that data to the `self.table_data` state var. We also create a button that allows us to start and pause the streaming of the data by changing the value of the boolean state var `running` using the event handler `toggle_pause`. If the `running` state var is set to `True` we stream the API data, when it is set to `False` we break out of the `while` loop and end the background event. | |
Here we use a [Background Task](docs/advanced-guide/background-tasks) to stream the data into the table without blocking UI interactivity. We call an advice API using `httpx` and then append that data to the `self.table_data` state var. We also create a button that allows us to start and pause the streaming of the data by changing the value of the boolean state var `running` using the event handler `toggle_pause`. If the `running` state var is set to `True` we stream the API data, when it is set to `False` we break out of the `while` loop and end the background event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually doesn't seem to work, so changed it back
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
No description provided.