rakutentech/r10/2.1.3

NOTE: the latest version is 7.0.0

R10.Table

type Column data msg

Describes how to turn data into a column in your table.

{ name : String
, viewCell : Palette -> Maybe data -> Element msg
, viewHeader : Palette -> HeaderInfo msg -> Element msg
, sorter : Sorter data
}
-> Column data msg
{ name : String
, toStr : data -> String
}
-> Column data msg
{ name : String
, toStr : data -> String
, maybeToCmp : Maybe (data -> comparable)
, maybeAttrs :
Maybe
{ header : List (Attribute msg)
, cell : List (Attribute msg)
}
}
-> Column data msg
{ name : String
, viewCell : Palette -> Maybe data -> Element msg
, viewHeader : Palette -> HeaderInfo msg -> Element msg
, maybeToCmp : Maybe (data -> comparable)
}
-> Column data msg
{ toId : data -> String
, toMsg : Msg -> msg
, columns : List (Column data msg)
}
-> Config data msg

Create the Config for your view function. Everything you need to render your columns efficiently and handle selection of columns.

Say we have a List Person that we want to show as a table. The table should have a column for name and age. We would create a Config like this:

import Table


type Msg = NewTableTable.Model.State R10.Table.Internal.State.State | ...


config : R10.Table.Internal.Config Person Msg
config =
  R10.Table.config
    { toId = .name
    , toMsg = NewTableTable.Model.State
    , columns =
        [ R10.Table.stringColumn "Name" .name
        , R10.Table.intColumn "Age" .age
        ]
    }

You provide the followerLimiting information in your table configuration:

  • toId — turn a Person into a unique ID. This lets us use Html.Keyed under the hood to make resorts faster.
  • columns — specify some columns to show.
  • toMsg — a way to send new table states to your app as messages.

See the examples to get a better feel for this!

(Maybe data -> Element msg)
-> Int
-> (Maybe data -> Bool)
-> (Maybe data -> Bool)
-> Config data msg
-> Config data msg
{ toId : data -> String
, toMsg : Msg -> msg
, columns : List (Column data msg)
, bodyAttrs : List (Attribute msg)
, rowAttrsBuilder : Maybe data -> List (Attribute msg)
, pagination : Maybe PaginationConfig
, filters : Maybe FiltersConfig
}
-> Config data msg

Just like config but you can specify a bunch of table customizations.

getActiveFilters : State -> Dict String String
getPaginationStateRecord : State -> Maybe PaginationStateRecord
initialStateFilters : { filterValues : Dict String String } -> State -> State
initialStatePagination : { length : Int } -> State -> State
{ name : String
, isReversed : Bool
}
-> State

Create a table state. By providing a column name, you determine which column should be used for sorting by default. So if you want your table of yachts to be sorted by length by default, you might say:

import Table


R10.Table.initialSort "Length"
isLoading : State -> Bool
isLoadingByPagination : State -> Bool
paginationButtonEnableAll : State -> State
paginationButtonNextFetch : State -> State
paginationButtonPrevFetch : State -> State
setLoading : Bool -> State -> State
updatePaginationState : PaginationStateRecord -> State -> State
view : Palette -> Config data msg -> State -> List data -> Element msg

Take a list of data and turn it into a table. The Config argument is the configuration for the table. It describes the columns that we want to show. The Table.State.State argument describes which column we are sorting by at the moment.

Note: The Table.State.State and List data should live in your Model. The Config for the table belongs in your view code. I very strongly recommend against putting Config in your model. Describe any potential table configurations statically, and look for a different library if you need something crazier than that.

Palette
-> State
-> List (ColumnConf data msg)
-> (String -> Bool -> msg)
-> Element msg
type alias State =
State