Skip to content

Tables

Tables allow you to list elements in a collection of data. They generally reside on the List pages apart of your resources.

Creating a new table

You can create a new table with a slug of "users" as so:

go
func MyNewTable() {
    // With code generation
    Table("users") // A new users table 

    // Without code generation
    // where T is the underlying model for your table.
    table.NewTable[T]("users") 
}

Drivers

Your table requires a driver in order to populate itself with data.

TIP

Specifying a driver is optional if your table is attached a resource. The resource will set it for you.

go
// where T is underlying model & db is your GORM db pointer.
myDriver := drivers.NewGormDriver[T](db) 

Table("users").
    Driver(myDriver)

Columns

You can attach a list of columns to your table using the Columns() method:

go
Table("users").
    Columns(
        ImageColumn("profile-pic"),
        TextColumn("name"),
        BadgeColumn("age"),
        //...
    )

Filters

You can attach a list of filters to your table using the Filters() method:

go
Table("users").
    Filters(
        TextFilter("age_over_25"),
        DateFilter("birthday_before"),
        //...
    )

Actions

You can attach a list of row actions to your columns using the Actions() method

go
Table("users").
    Actions(
        RowAction("delete"),
        RowAction("duplicate")
        //...
    )

BulkActions

You can attach bulk actions that operate over a selection of rows using the BulkActions() method:

go
Table("users").
    BulkActions(
        BulkAction("delete_all"),
        BulkAction("run_report"),
    )

ClickURL

The ClickURL method allows you to define what URL to visit when a user clicks one of your record rows:

go
// static
Table("users").
    ClickUrl("/admin/") // all rows visit the dashboard when clicked

// callback
Table("users").
    ClickUrlFn(
        func(ctx *context.TableRowContext[models.User]) string {
            // Redirect to a user's view page on click.
            return fmt.Sprintf("/admin/users/%d/view", ctx.Model.ID)
        },
    )

By default, clicking table rows does nothing. Providing ClickURL with an empty string will also prevent redirects on click.

Polling

You can enable table polling with the Poll method:

go
// Static
Table("users").
    Poll() // Will poll every 5 seconds or 5000ms

// static with rate
Table("users").
    PollMs(500) // will start polling every 500ms

// callback
Table("users").
    PollMsFn(
        func(ctx *context.ColumnContext) int {
            return 5000 // every 5000 ms
        }
    )

Returning a 0 as the poll value in PollMs or PollMsFn will prevent your table from polling.

INFO

Polling does not occur for your users if their mouse is hovered over your table.

Infinite Scrolling

You can enable infinitely scrolling tables by applying the InfiniteScroll method:

go
Table("users").
    InfiniteScroll()

Infinite scroll will fetch the same amount of records as your default pagination option for each additional request.

Notes

  • Infinte scroll & polling don't get along nice. Please don't enable them both.
  • Infinite scroll is not virtualized. This will come in the future.
  • There are no pagination options while infintely scrolling
  • Infinite scroll pages are not preserved when leaving or re-visiting your page.

Bulk Actions Position

You can change the position of your bulk actions using the BulkActionPosition method:

There are three supported positions:

  1. Header
  2. Footer
  3. Hidden
go
import "github.com/iridiumgo/iridium/core/table/config"

// static
Table("user").
    BulkActionPosition(config.BulkActionsHeader). // Place in header - default
    BulkActionPosition(config.BulkActionsFooter). // Place in footer
    BulkActionPosition(config.BulkActionsHidden)  // Hide

// callback
Table("users").
    BulkActionPositionFn(
        func(ctx *context.ColumnContext) config.BulkActionsPosition{
            return config.BulkActionsHeader
        }
    )

Active Filters Position

You can change the position of your active filters section using the BulkActionPosition method:

There are three supported positions:

  1. Header
  2. Footer
  3. Hidden
go
import "github.com/iridiumgo/iridium/core/table/config"

// static
Table("user").
    ActiveFilterPosition(config.ActiveFilterHeader). // Place in header - default
    ActiveFilterPosition(config.ActiveFilterFooter). // Place in footer
    ActiveFilterPosition(config.ActiveFilterHidden)  // Hide

// callback
Table("users").
    ActiveFilterPositionFn(
        func(ctx *context.ColumnContext) config.BulkActionsPosition{
            return config.ActiveFilterHeader
        }
    )

Released under the MIT License.