Element.table accepts data as part of a record for its second argument:
table :
List (Attribute msg)
-> { data : List records
, columns : List (Column records msg)
}
-> Element msg
I think it would be useful to have data as the third argument instead:
table :
List (Attribute msg)
-> List (Column records msg)
-> List records
-> Element msg
This change would enable the use of pipes and currying with Element.table:
people
|> List.filter (.name >> (==) "Example")
|> List.sortBy .age
|> Element.table []
[ { header = text "Name"
, width = fill
, view = \{ name } -> text name
}
, { header = text "Age"
, width = fill
, view = \{ age } -> text (String.fromInt age)
}
]
tableOfPeople : List Person -> Element msg
tableOfPeople =
Element.table []
[ { header = text "Name"
, width = fill
, view = \{ name } -> text name
}
, { header = text "Age"
, width = fill
, view = \{ age } -> text (String.fromInt age)
}
]
Currently, the equivalent of the above examples look like this:
Element.table []
{ data =
people
|> List.filter (.name >> (==) "Example")
|> List.sortBy .age
, columns =
[ { header = text "Name"
, width = fill
, view = \{ name } -> text name
}
, { header = text "Age"
, width = fill
, view = \{ name } -> text name
}
]
}
tableOfPeople : List Person -> Element msg
tableOfPeople people =
Element.table []
{ data = people
, columns =
[ { header = text "Name"
, width = fill
, view = \{ name } -> text name
}
, { header = text "Age"
, width = fill
, view = \{ age } -> text (String.fromInt age)
}
]
}
I guess functions like indexedTable would also benefit from such a change - I'm not sure if there is anything else in elm-ui that accepts data like Element.table but it'd be good to consider those too.
Element.table
accepts data as part of a record for its second argument:I think it would be useful to have data as the third argument instead:
This change would enable the use of pipes and currying with
Element.table
:Currently, the equivalent of the above examples look like this:
Related Slack thread.