Columns
Columns are where you define and configure what and how data will be displayed in your table.
Iridium currently supports the following columns:
Columns have a list of shared methods. Certain methods apply to the column itself, while others can configure each individual cell within that column.
Label
The Label method allows you to define a custom label for this column.
// static
TextColumn("name").
Label("Name")
// callback
TextColumn("name").
LabelFn(func(ctx *ctxDriver.Column) string {
return "Name"
})Sortable
The Sortable method indicates that this row can be sorted by your user.
INFO
Iridium provides default implementations for sorting for your data rows based on your chosen driver
// static
TextColumn("name").
Sortable()
// callback
TextColumn("name").
SortableFn(func(ctx *ctxDriver.Column) bool {
return true
})Searchable
The Searchable method indicates that this row should be searchable by your user. If any field had the Searchable method applied, a search box will appear on your table. Searchable can be applied to as many columns as needed, and all will be searched at the same time.
INFO
Iridium provides default implementations for searching for your data rows based on your chosen driver
// static
TextColumn("name").
Searchable()
// callback
TextColumn("name").
SearchableFn(func(ctx *ctxDriver.Column) bool {
return true
})State
The State method allows hooking into the cell value before it is rendered, allowing you to modify the value before it is displayed on a per-cell/per-record basis.
// static
TextColumn("name").
State("Joe Smith") // All cells under the name column will be set to "Joe Smith"
// callback
TextColumn("name").
StateFn(func(value string, ctx *ctxDriver.TableCell[T]) string {
return strings.ToUpper(value) // Always uppercase names
})SortQueryUsing
The SortQueryUsing method allows you to define a custom sort query for this column. The method inject for you to describe this behaviour is dependent on your chosen driver and generated through type-aliasing.
// GormDriver
TextColumn("name").
SortQueryUsing(func(query *gorm.DB, ctx *ctxDriver.ColumnSortQueryContext) {
query.Order("name " + ctx.Direction)
})
// ArrayDriver - where T is your model type
TextColumn("name").
SortQueryUsing(func(a, b *T, ctx *ctxDriver.ColumnSortQueryContext) bool {
return strings.Compare(a.Name, b.Name) > 0
}).SearchQueryUsing
The SearchQueryUsing method allows you to define a custom search query for this column. The method inject for you to describe this behaviour is dependent on your chosen driver and generated through type-aliasing.
// GormDriver
TextColumn("name").
SearchQueryUsing(func(query *gorm.DB, ctx *ctxDriver.ColumnSearchQueryContext) {
query.Where("name LIKE ?", "%"+ctx.Value+"%")
})
// ArrayDriver - where T is your model type
TextColumn("name").
SearchQueryUsing(func(data *T, ctx *ctxDriver.ColumnSearchQueryContext) bool {
return strings.Contains(data.Name, ctx.Value)
}),Cell Attributes
The CellAttributes method allows you to provide a list of attributes on a per-cell basis. This means you can change how cells look, behave, etc., using any attribute
// static
TextColumn("name").
CellAttributes(map[string]any{
"style": "color:red", // This will apply to all cell columns.
})
// callback
TextColumn("name").
CellAttributesFn(
func (ctx CellContext) map[string]any {
if strings.Contains(ctx.Model.Name, "Joe") {
return map[string]any {
"style": "color: blue"
}
}
return map[string]any {
"style": "color: green"
}
}
)