Tables are a matrixial data disposition with rows, columns, headers, and cells.
UI.Tables are type-safe, which means that every row needs to have the same number of columns (including the headers). Otherwise, compilation fails.
Stateful.table
{ toExternalMsg = Msg.ForTable
, columns = Book.tableColumns
, toRow = Book.toTableRow
, state = model.tableState
}
|> Stateful.withResponsive
{ toDetails = Book.toTableDetails
, toCover = Book.toTableCover
}
|> Stateful.withWidth (Element.fill |> Element.maximum 640)
|> Stateful.withItems
[ Book "Dan Brown" "Angels & Demons" "2000"
, Book "Dan Brown" "The Da Vinci Code" "2003"
, Book "Dan Brown" "The Lost Symbol" "2009"
, Book "Dan Brown" "Inferno" "2013"
, Book "Dan Brown" "Origin" "2017"
]
|> Stateful.renderElement renderConfigWhere Book is:
type alias Book =
{ author : String, title : String, year : String }
tableColumns =
columnsEmpty
|> column "Title" (columnWidthPixels 320)
|> column "Author" (columnWidthPixels 240)
|> column "Year" (columnWidthPixels 120)
toTableRow { author, title, year } =
rowEmpty
|> rowCellText (Text.body1 title)
|> rowCellText (Text.body2 author)
|> rowCellText (Text.caption year)
toTableDetails { author, title } =
detailsEmpty
|> detailHidden
|> detailShown { label = "Author", content = cellFromText <| Text.body2 author }
|> detailHidden
toTableCover { title, year } =
{ title = title, caption = Just year }
someFilters =
filtersEmpty
|> localSingleTextFilter Nothing .title
|> localSingleTextFilter (Just "Dan") .author
|> localSingleTextFilter Nothing .yearAnd on model:
{ -...
, tableState : Stateful.Table Msg.Msg TypeNumbers.Three
}
{ -...
, tableState = Stateful.withFilters Book.someFilters Stateful.init
}Record with parameters for the creation of a StatefulTable.
This is record that constrains type-safe sized-arrays.
See TypeNumbers for how to compose its phantom type.
{ toExternalMsg = Msg.ForTable
, columns = Book.tableColumns
, toRow = Book.toTableRow
, state = model.tableState
}Constructs a stateful table from its columns and rows. Also defines the handling function for messages, and the current table's state.
table
{ columns = Book.tableColumns
, toRow = Book.toTableRow
, toExternalMsg = Msg.ForTable
, state = model.tableState
}Each of these items will become a row in this table.
withItems
[ Book "Dan Brown" "Angels & Demons" "2000"
, Book "Dan Brown" "The Da Vinci Code" "2003"
, Book "Dan Brown" "The Lost Symbol" "2009"
, Book "Dan Brown" "Inferno" "2013"
, Book "Dan Brown" "Origin" "2017"
]
someTableRequired information for displaying the mobile's layout.
This is record that constrains type-safe sized-arrays.
See TypeNumbers for how to compose its phantom type.
{ toDetails = Book.toTableDetails
, toCover = Book.toTableCover
}What is displayed in a collapsed mobile's row.
{ title = "Foo Fighters - Everlong"
, caption = Just "Morumbi - São Paulo 2015-01-23"
}A set of Detail msg.
Must have the same amount of elements as cells do in the table's row.
Used to render a cell in the mobile's layout.
Allows a table to have a responsive layout when on mobile.
withResponsive
{ toDetails = Book.toTableDetails
, toCover = Book.toTableCover
}
someTableAn empty Details set.
toTableDetails { author, title } =
detailsEmpty
|> detailHidden
|> detailShown
{ label = "Author"
, content = cellFromText (Text.body2 author)
}
|> detailHiddenDefines that a cell will be shown in the mobile's layout.
detailShown
{ label = "Edit"
, content = cellFromButton editButton
}
detailsSetDefines that a cell will be hidden in the mobile's layout.
detailsEmpty
|> detailHidden
|> detailHidden
|> detailHiddenKeep this one in your Model, it holds the table's current state.
The Stateful.Msg handles stateful table's related messages.
The correct way of instantiating a Table.State.
{ -- ...
, tableState = Stateful.init
-- ...
}Given a message, apply an update to the Table.State.
Do not ignore the returned Cmd, it may include remote filter's messages.
( newModel, newCmd ) =
Table.update subMsg oldModel.tableStateArray with all the columns' filters and their initial state.
This is a type-safe sized-array.
See TypeNumbers for how to compose its phantom type.
An empty Filters set.
toTableDetails { author, title } =
filtersEmpty
|> localSingleTextFilter Nothing .title
|> localSingleTextFilter (Just "Dan") .author
|> localSingleTextFilter Nothing .yearApply filters defintion to a table's State.
model =
stateWithFilters Book.filtersInit initA filter with one single text field. Only part of the content must match the filter's input. Filtering logic is applied internally by the component.
localSingleTextFilter
maybeInitialValue
mapItemToStringA filter with one single text field.
Only part of the content must match the filter's input.
Filtering logic is applied through an external message.
When Nothing is applied to the message, it means to clear the current filter.
remoteSingleTextFilter
maybeInitialValue
Msg.ApplyFilterA filter with multiple text field. The content must match at least one of those fields otherwise it's filtered out. Only part of the content must match the filter's input. Filtering logic is applied internally by the component.
localMultiTextFilter
[]
mapItemToStringFor having an initial filter applied:
localMultiTextFilter
[ "initial", "fields" ]
mapItemToStringA filter with multiple text field. The content must match at least one of those fields otherwise it's filtered out. Only part of the content must match the filter's input.
Filtering logic is applied through an external message. When an empty list is applied to the message, it means to clear the current filter.
remoteMultiTextFilter
[ "initial", "fields" ]
Msg.ApplyFilterA filter for dates with one single field. Filtering logic is applied internally by the component.
localSingleDateFilter timeZone
(Just somePosixEpoch)
mapItemToPosixEpochA filter for dates with one single field.
Filtering logic is applied through an external message.
When Nothing is applied to the message, it means to clear the current filter.
remoteSingleDateFilter
maybeInitialPosix
Msg.ApplyFilterA filter for dates in an expected range. The range is defined using two date fields. Filtering logic is applied internally by the component.
localRangeDateFilter timeZone
(Just datesAfterThis)
(Just datesBeforeThis)
mapItemToPosixEpochNOTE: Hours, minutes and seconds are discarded from the range limits.
A filter for dates in an expected range. The range is defined using two date fields.
Filtering logic is applied through an external message.
When Nothing is applied to the message, it means to clear the current filter.
remoteRangeDateFilter timeZone
(Just datesAfterThis)
(Just datesBeforeThis)
Msg.ApplyFilterNOTE: Hours, minutes and seconds are discarded from the range limits.
When comparing if dates are the same.
When comparing if some date is after another.
When comparing if some date is before another.
A filter for a single date, dates before specified date, or dates after specified date. The filter-case is defined using radio buttons. Filtering logic is applied internally by the component.
localPeriodDateFilter timeZone
(Just somePosixEpoch)
(Just periodAfter)
mapItemToPosixEpochNOTE: Hours, minutes and seconds are discarded from the range limits.
A filter for a single date, dates before specified date, or dates after specified date. The filter-case is defined using radio buttons.
Filtering logic is applied through an external message.
When Nothing is applied to the message, it means to clear the current filter.
remotePeriodDateFilter timeZone
(Just somePosixEpoch)
(Just periodAfter)
Msg.ApplyFilterNOTE: Hours, minutes and seconds are discarded from the range limits.
A filter for custom radio buttons. Filtering logic is applied internally by the component.
localSelectFilter
[ "Option 1"
, "Option 2"
]
(Just 1)
mapItemEachOptionToBoolA filter for custom radio buttons.
Filtering logic is applied through an external message.
When Nothing is applied to the message, it means to clear the current filter.
remoteSelectFilter
[ "Option 1"
, "Option 2"
]
(Just 1)
Msg.ApplyFilterApplies Element.width to the component.
Table.withWidth
(Element.fill |> Element.minimum 220)
someTableEnd of the builder's life. The result of this function is a ready-to-insert Elm UI's Element.
The
StatefulTable msg item columnstype is used for describing the component for later rendering.This is type that constrains type-safe sized-arrays. See
TypeNumbersfor how to compose its phantom type.