This is a library that provides an abstraction for building HTML tables. A table is
parameterized over a foundation type site
and any type a
. The table is a collection
of columns, where each column has two parts:
- A title:
WidgetT site IO ()
- A function for visualizing the data:
a -> WidgetT site IO ()
In the examples folder, there is a single-file yesod application that demonstrates
how yesod-table works. It first shows how the Monoid
instance is used to build
smaller pieces into a larger table, and then it combines those tables, making
use of the Contravariant
instance.
Here is a simple example:
import Yesod
import qualified Yesod.Table as Table
import Yesod.Table (Table)
import Data.Text (Text)
data Person = Person
{ firstName :: Text
, lastName :: Text
, age :: Int
}
myTable :: Table App Person
myTable = mempty
<> Table.text "First Name" firstName
<> Table.text "Last Name" lastName
<> Table.int "Age" age
Then, you can render the table by providing it with rows of data. So, in a handler somewhere, you could write:
getHomeR :: Handler Html
getHomeR = defaultLayout $ Table.buildBootstrap myTable
[ Person "Drew" "Martin" 23
, Person "Alexa" "Martin" 23
]
The home page would have a table with two rows.