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 =
{ toKey = .title, toTableRowView}
toTableRowView { 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.stateWithFilters 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
}DEPRECATED: Use stateWithItems instead. Otherwise, by using this you'll be discarding sorting and fitlering.
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.tableStateEach of these items will become a row in this table.
stateWithItems
[ 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"
]
someTableStateArray 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.ApplyFilterArray with all the columns' sorting definitions.
This is a type-safe sized-array.
See TypeNumbers for how to compose its phantom type.
Apply sortings defintion to a table's State.
model =
stateWithSorters Book.sortersInit initAn empty Sorters set.
sortersInit =
sortersEmpty
|> sortBy .title
|> sortBy .author
|> unsortableAllow sorting a column alphabetically.
sortersInit =
sortersEmpty
|> sortBy .title
|> sortBy .author
|> unsortableAllow sorting a column using a Float value.
sortersInit =
sortersEmpty
|> unsortable
|> sortByFloat .value
|> sortByFloat .timestamp
|> sortByFloat .averageAllow sorting a column using an Integer value.
sortersInit =
sortersEmpty
|> unsortable
|> sortByInt .count
|> sortByInt .areaCode
|> sortByInt .hourAllow sorting a column using a Char value.
sortersInit =
sortersEmpty
|> unsortable
|> sortByChar .firstLetterAllow sorting a column with a custom function.
Check List.sortWith
sortersInit =
sortersEmpty
|> unsortable
|> sortWith flippedComparisonDescribes that some column is not sortable.
sortersInit =
sortersEmpty
|> sortBy .title
|> sortBy .author
|> unsortableChanges the initial sorting to some columns as descreasing.
model =
stateWithSorters
(Book.sortersInit |> sortDecreasing 1)
initChanges the initial sorting to some columns as increasing.
model =
stateWithSorters
(Book.sortersInit |> sortIncreasing 1)
initApplies Element.width to the component.
Table.withWidth
(Element.fill |> Element.minimum 220)
someTableApply selection defintion to a table's State.
model =
stateWithSelection Book.getISBN initResolves if one item's row is or not selected.
isHungerGamesSelected =
Table.stateIsSelected hungerGamesBook tableStateTODO: withRemoteSelection
End 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.