krisajenkins/elm-exts/20.0.0

NOTE: this package is not compatible with Elm 0.19.1

Exts.Html.Table

Helpers for simple data tables. Define how a list of items can be rendered as a table. The definition is a List of (column-title, column-value-accessor) pairs.

I find this approach works well for simple tables, but breaks down as soon as you need much customisation. Use it to get you started quickly, but be ready to rewrite when this 80% case no longer suits.

type alias CellDef a =
( Html, a -> Html )

A table definition looks something like:

[(text "Name", .name >> text)
,(text "Name", .age >> toString >> text)]
type alias TableDef a =
List (CellDef a)
simpleTable : TableDef a -> List a -> Html

Given a table definition, render a list of elements as HTML.

simpleTableRow : TableDef a -> a -> Html

Given a table definition, render an element to a <tr> tag. This is lower-level. Usually you will want simpleTable instead.

titleGroup : List String -> Html

titleGroup and valueGroup are used to create columns that stack multiple pairs. For example:

[(titleGroup ["Latitude", "Longitude"]
 ,valueGroup [.location >> .lat >> toString >> text
             ,.location >> .lng >> toString >> text])
valueGroup : List (a -> Html) -> a -> Html