Skip to main content

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.
str_id
const char*
Unique identifier for the table
columns
int
Number of columns
flags
ImGuiTableFlags
default:"0"
Table flags (see ImGuiTableFlags_)
outer_size
const ImVec2&
default:"ImVec2(0.0f, 0.0f)"
Outer size of table
inner_width
float
default:"0.0f"
Inner width of table (for horizontal scrolling)
return
bool
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

void ImGui::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_)
min_row_height
float
default:"0.0f"
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.
return
bool
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.
column_n
int
Column index (0-based)
return
bool
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.
label
const char*
Column label (also used as ID unless user_id is provided)
flags
ImGuiTableColumnFlags
default:"0"
Column flags (see ImGuiTableColumnFlags_)
init_width_or_weight
float
default:"0.0f"
Initial width (for fixed columns) or weight (for stretch columns)
user_id
ImGuiID
default:"0"
Optional user ID
// 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();
}

TableSetupScrollFreeze

void ImGui::TableSetupScrollFreeze(int cols, int rows)
Lock columns/rows so they stay visible when scrolled.
cols
int
Number of columns to freeze
rows
int
Number of rows to freeze
// Example - freeze first column and header row
ImGui::TableSetupScrollFreeze(1, 1);

TableHeadersRow

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();
}

TableHeader

void ImGui::TableHeader(const char* label)
Submit one header cell manually (rarely used).
label
const char*
Header label

TableAngledHeadersRow

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).
return
ImGuiTableSortSpecs*
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()).
return
int
Number of columns

TableGetColumnIndex

int ImGui::TableGetColumnIndex()
Return current column index.
return
int
Current column index

TableGetRowIndex

int ImGui::TableGetRowIndex()
Return current row index (header rows are accounted for).
return
int
Current row index

TableGetColumnName

const char* ImGui::TableGetColumnName(int column_n = -1)
Return column name. Pass -1 to use current column.
column_n
int
default:"-1"
Column index (-1 = current column)
return
const char*
Column name or empty string

TableGetColumnFlags

ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n = -1)
Return column flags. Pass -1 to use current column.
column_n
int
default:"-1"
Column index (-1 = current column)
return
ImGuiTableColumnFlags
Column flags

TableSetColumnEnabled

void ImGui::TableSetColumnEnabled(int column_n, bool v)
Change user accessible enabled/disabled state of a column.
column_n
int
Column index
v
bool
Enabled state

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.
return
int
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
ImGuiTableBgTarget
Target type (see ImGuiTableBgTarget_)
color
ImU32
RGBA color packed as 32-bit
column_n
int
default:"-1"
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.

Build docs developers (and LLMs) love