@@ -118,6 +118,8 @@ type alias Column row msg =
118118 { name : ColumnName
119119 , renderHtml : row -> Html msg
120120 , ordering : Ordering row
121+ , columnAttrs : List ( Attribute msg)
122+ , entryAttrs : List ( Attribute msg)
121123 }
122124
123125
@@ -197,16 +199,16 @@ type alias CsvExportData =
197199The defaults should be fine, but customizations can be added and defined depending on each case.
198200-}
199201type alias Customizations row msg =
200- { tableContainerAttrs : List ( Attribute ( Msg msg) )
201- , tableAttrs : List ( Attribute ( Msg msg) )
202- , optionsHeaderAttrs : List ( Attribute ( Msg msg) )
202+ { tableContainerAttrs : List ( Attribute msg)
203+ , tableAttrs : List ( Attribute msg)
204+ , optionsHeaderAttrs : List ( Attribute msg)
203205
204206 -- , caption : Maybe (HtmlDetails msg)
205- , theadAttrs : List ( Attribute ( Msg msg) )
207+ , theadAttrs : List ( Attribute msg)
206208
207209 -- , tfoot : Maybe (HtmlDetails msg)
208- , tbodyAttrs : List ( Attribute ( Msg msg) )
209- , rowAttrs : row -> List ( Attribute ( Msg msg) )
210+ , tbodyAttrs : List ( Attribute msg)
211+ , rowAttrs : row -> List ( Attribute msg)
210212 }
211213
212214
@@ -779,19 +781,22 @@ encodeStorageEffect key filter =
779781view : Model row msg -> Html (Msg msg )
780782view ( Model ( { columns, data, options } as model)) =
781783 let
784+ mapAttribute =
785+ Html . Attributes . map ParentMsg
786+
782787 theadAttrs =
783- options. customizations. theadAttrs
788+ options. customizations. theadAttrs |> List . map mapAttribute
784789
785790 tbodyAttrs =
786- options. customizations. tbodyAttrs
791+ options. customizations. tbodyAttrs |> List . map mapAttribute
787792
788793 tableContainerAttrs =
789- options. customizations. tableContainerAttrs
794+ options. customizations. tableContainerAttrs |> List . map mapAttribute
790795
791796 tableView =
792- table options. customizations. tableAttrs
797+ table ( options. customizations. tableAttrs |> List . map mapAttribute )
793798 [ thead theadAttrs [ tableHeader columns model ]
794- , tbody tbodyAttrs ( tableBody columns data)
799+ , tbody tbodyAttrs ( tableBody columns data options . customizations . rowAttrs )
795800 ]
796801
797802 content =
@@ -800,7 +805,7 @@ view (Model ({ columns, data, options } as model)) =
800805 [ tableView ]
801806
802807 elems ->
803- [ div options. customizations. optionsHeaderAttrs elems
808+ [ div ( options. customizations. optionsHeaderAttrs |> List . map mapAttribute ) elems
804809 , tableView
805810 ]
806811 in
@@ -907,15 +912,17 @@ tableHeader columns sort =
907912 tr [ class " head" ]
908913 ( columns
909914 |> NonEmptyList . toList
910- |> List . map ( \ column -> ( column. name, thClass sort column. name ))
915+ |> List . map ( \ column -> ( column. name, thClass sort column. name, column . columnAttrs ))
911916 |> List . map
912- ( \ ( ColumnName name, thClassValue ) ->
917+ ( \ ( ColumnName name, thClassValue, columnAttrs ) ->
913918 th
914- [ class thClassValue
915- , rowspan 1
916- , colspan 1
917- , onClick ( SortColumn ( ColumnName name))
918- ]
919+ ( [ class thClassValue
920+ , rowspan 1
921+ , colspan 1
922+ , onClick ( SortColumn ( ColumnName name))
923+ ]
924+ ++ List . map ( Html . Attributes . map ParentMsg ) columnAttrs
925+ )
919926 [ text name ]
920927 )
921928 )
@@ -935,15 +942,19 @@ thClass { sortBy, sortOrder } columnName =
935942 " sorting"
936943
937944
938- tableBody : NonEmptyList .Nonempty (Column row msg ) -> List row -> List (Html (Msg msg ))
939- tableBody columns data =
945+ tableBody : NonEmptyList .Nonempty (Column row msg ) -> List row -> ( row -> List ( Attribute msg )) -> List (Html (Msg msg ))
946+ tableBody columns data rowAttrs =
940947 let
941948 rowTable n =
942- tr []
949+ tr ( List . map ( Html . Attributes . map ParentMsg ) ( rowAttrs n ))
943950 ( columns
944951 |> NonEmptyList . toList
945- |> List . map ( \ { renderHtml } -> Html . map ParentMsg ( n |> renderHtml))
946- |> List . map ( \ s -> td [] [ s ] )
952+ |> List . map
953+ ( \ { renderHtml, entryAttrs } ->
954+ td
955+ ( List . map ( Html . Attributes . map ParentMsg ) entryAttrs)
956+ [ Html . map ParentMsg ( n |> renderHtml) ]
957+ )
947958 )
948959 in
949960 if List . length data > 0 then
0 commit comments