Table Functions
Full-featured replacement for old Columns API. See demo for usage examples.
BeginTable
bool ImGui::BeginTable(const char* str_id, int columns, ImGuiTableFlags flags = 0, const ImVec2& outer_size = ImVec2(0.0f, 0.0f), float inner_width = 0.0f)
Begin a table. Only call EndTable() if this returns true.
Unique identifier for the table
flags
ImGuiTableFlags
default:"0"
Table flags (see ImGuiTableFlags_)
outer_size
const ImVec2&
default:"ImVec2(0.0f, 0.0f)"
Outer size of table
Inner width of table (for horizontal scrolling)
True if table is visible and can be appended to
// Example
if (ImGui::BeginTable("table1", 3)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Row 0, Col 0");
ImGui::TableSetColumnIndex(1);
ImGui::Text("Row 0, Col 1");
ImGui::TableSetColumnIndex(2);
ImGui::Text("Row 0, Col 2");
ImGui::EndTable();
}
EndTable
End table. Only call if BeginTable() returns true.
TableNextRow
void ImGui::TableNextRow(ImGuiTableRowFlags row_flags = 0, float min_row_height = 0.0f)
Append into the first cell of a new row.
row_flags
ImGuiTableRowFlags
default:"0"
Row flags (see ImGuiTableRowFlags_)
Minimum row height (includes CellPadding.y * 2.0f)
// Example
for (int row = 0; row < 10; row++) {
ImGui::TableNextRow();
for (int column = 0; column < 3; column++) {
ImGui::TableSetColumnIndex(column);
ImGui::Text("Row %d Column %d", row, column);
}
}
TableNextColumn
bool ImGui::TableNextColumn()
Append into the next column (or first column of next row if currently in last column). Return true when column is visible.
True when column is visible
// Example
for (int row = 0; row < 10; row++) {
for (int column = 0; column < 3; column++) {
ImGui::TableNextColumn();
ImGui::Text("Cell %d,%d", row, column);
}
}
TableSetColumnIndex
bool ImGui::TableSetColumnIndex(int column_n)
Append into the specified column. Return true when column is visible.
True when column is visible
Table Setup
TableSetupColumn
void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags = 0, float init_width_or_weight = 0.0f, ImGuiID user_id = 0)
Specify label, resizing policy, default width/weight, ID, various other flags for a column.
Column label (also used as ID unless user_id is provided)
flags
ImGuiTableColumnFlags
default:"0"
Column flags (see ImGuiTableColumnFlags_)
Initial width (for fixed columns) or weight (for stretch columns)
// Example
if (ImGui::BeginTable("table", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable)) {
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 100.0f);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Size", ImGuiTableColumnFlags_WidthFixed, 80.0f);
ImGui::TableHeadersRow();
for (int n = 0; n < 100; n++) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%d", n);
ImGui::TableNextColumn();
ImGui::Text("Item %d", n);
ImGui::TableNextColumn();
ImGui::Text("1234");
}
ImGui::EndTable();
}
void ImGui::TableSetupScrollFreeze(int cols, int rows)
Lock columns/rows so they stay visible when scrolled.
Number of columns to freeze
// Example - freeze first column and header row
ImGui::TableSetupScrollFreeze(1, 1);
void ImGui::TableHeadersRow()
Submit a row with headers cells based on data provided to TableSetupColumn() and submit context menu.
// Example
if (ImGui::BeginTable("table", 3)) {
ImGui::TableSetupColumn("ID");
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Value");
ImGui::TableHeadersRow();
// Table content...
ImGui::EndTable();
}
void ImGui::TableHeader(const char* label)
Submit one header cell manually (rarely used).
void ImGui::TableAngledHeadersRow()
Submit a row with angled headers for every column with the ImGuiTableColumnFlags_AngledHeader flag. Must be first row.
Table Query
TableGetSortSpecs
ImGuiTableSortSpecs* ImGui::TableGetSortSpecs()
Get latest sort specs for the table (NULL if not sorting).
Sort specifications or NULL
// Example
if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs()) {
if (sort_specs->SpecsDirty) {
// Sort your data
MyData::SortWithSortSpecs(sort_specs);
sort_specs->SpecsDirty = false;
}
}
TableGetColumnCount
int ImGui::TableGetColumnCount()
Return number of columns (value passed to BeginTable()).
TableGetColumnIndex
int ImGui::TableGetColumnIndex()
Return current column index.
TableGetRowIndex
int ImGui::TableGetRowIndex()
Return current row index (header rows are accounted for).
TableGetColumnName
const char* ImGui::TableGetColumnName(int column_n = -1)
Return column name. Pass -1 to use current column.
Column index (-1 = current column)
Column name or empty string
TableGetColumnFlags
ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n = -1)
Return column flags. Pass -1 to use current column.
Column index (-1 = current column)
TableSetColumnEnabled
void ImGui::TableSetColumnEnabled(int column_n, bool v)
Change user accessible enabled/disabled state of a column.
TableGetHoveredColumn
int ImGui::TableGetHoveredColumn()
Return hovered column. Return -1 when table is not hovered. Return columns_count if the unused space at the right of visible columns is hovered.
Hovered column index or -1
TableSetBgColor
void ImGui::TableSetBgColor(ImGuiTableBgTarget target, ImU32 color, int column_n = -1)
Change the color of a cell, row, or column.
Target type (see ImGuiTableBgTarget_)
RGBA color packed as 32-bit
Column index (-1 = current column)
// Example
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, IM_COL32(255, 0, 0, 255)); // Red cell
See the full tables documentation for flag descriptions and advanced examples.