2021-04-12 18:19:04 +02:00
```eval_rst
.. include:: /header.rst
:github_url: |github_link_base|/widgets/table.md
```
# Table (lv_table)
## Overview
Tables, as usual, are built from rows, columns, and cells containing texts.
2021-06-09 15:10:35 +02:00
The Table object is very lightweight because only the texts are stored. No real objects are created for cells but they are just drawn on the fly.
2021-04-12 18:19:04 +02:00
## Parts and Styles
2021-06-09 15:10:35 +02:00
- `LV_PART_MAIN` The background of the table uses all the typical background style properties.
- `LV_PART_ITEMS` The cells of the table also use all the typical background style properties and the text properties.
2021-04-12 18:19:04 +02:00
## Usage
### Set cell value
2021-06-09 15:10:35 +02:00
The cells can store only text so numbers need to be converted to text before displaying them in a table.
2021-04-12 18:19:04 +02:00
`lv_table_set_cell_value(table, row, col, "Content")` . The text is saved by the table so it can be even a local variable.
2021-06-09 15:10:35 +02:00
Line breaks can be used in the text like `"Value\n60.3"` .
2021-04-12 18:19:04 +02:00
2021-06-09 15:10:35 +02:00
New rows and columns are automatically added is required
2021-04-12 18:19:04 +02:00
2021-05-11 19:44:52 +02:00
### Rows and Columns
2021-04-12 18:19:04 +02:00
2021-05-11 19:44:52 +02:00
To explicitly set number of rows and columns use `lv_table_set_row_cnt(table, row_cnt)` and `lv_table_set_col_cnt(table, col_cnt)`
2021-04-12 18:19:04 +02:00
2021-05-11 19:44:52 +02:00
### Width and Height
2021-04-12 18:19:04 +02:00
2021-05-11 19:44:52 +02:00
The width of the columns can be set with `lv_table_set_col_width(table, col_id, width)` . The overall width of the Table object will be set to the sum of columns widths.
2021-04-12 18:19:04 +02:00
2021-05-11 19:44:52 +02:00
The height is calculated automatically from the cell styles (font, padding etc) and the number of rows.
2021-04-12 18:19:04 +02:00
### Merge cells
2021-06-09 15:10:35 +02:00
Cells can be merged horizontally with `lv_table_set_cell_merge_right(table, col, row, true)` . To merge more adjacent cells call this function for each cell.
2021-04-12 18:19:04 +02:00
### Scroll
2021-06-09 15:10:35 +02:00
If the label's width or height is set to `LV_SIZE_CONTENT` that size will be used to show the whole table in the respective direction.
2021-05-11 19:44:52 +02:00
E.g. `lv_obj_set_size(table, LV_SIZE_CONTENT, LV_SIZE_CONTENT)` automatically sets the table size to show all the columns and rows.
2021-06-09 15:10:35 +02:00
If the width or height is set to a smaller number than the "intrinsic" size then the table becomes scrollable.
2021-04-12 18:19:04 +02:00
## Events
2021-05-11 19:44:52 +02:00
- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for both main and items parts to allow hooking the drawing.
2021-06-09 15:10:35 +02:00
For more detail on the main part see the [Base object ](/widgets/obj#events )'s documentation.
For the items (cells) the following fields are used: `clip_area` , `draw_area` , `part` , `rect_dsc` , `label_dsc` `id` (current row × col count + current column).
2021-05-11 19:44:52 +02:00
2021-04-12 18:19:04 +02:00
Learn more about [Events ](/overview/event ).
## Keys
No *Keys* are processed by the object type.
Learn more about [Keys ](/overview/indev ).
## Example
```eval_rst
2021-05-13 16:13:47 +02:00
.. include:: ../../../examples/widgets/table/index.rst
2021-04-12 18:19:04 +02:00
```
### MicroPython
No examples yet.
## API
```eval_rst
.. doxygenfile:: lv_table.h
:project: lvgl
```