From 32f70235b815c0e86f1a902fdceb605e82a74cde Mon Sep 17 00:00:00 2001 From: Rehno Lindeque Date: Thu, 6 Jul 2017 03:29:19 +0000 Subject: [PATCH] Send the row index into rowFilter function This allows one to do client-side paging on a table while maintaining the sort order given by the columns. --- src/Table.elm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Table.elm b/src/Table.elm index cf8153c..60557dc 100644 --- a/src/Table.elm +++ b/src/Table.elm @@ -186,6 +186,7 @@ type alias Customizations data msg = , tfoot : Maybe (HtmlDetails msg) , tbodyAttrs : List (Attribute msg) , rowAttrs : data -> List (Attribute msg) + , rowFilter : Int -> data -> Bool } @@ -209,6 +210,7 @@ defaultCustomizations = , tfoot = Nothing , tbodyAttrs = [] , rowAttrs = simpleRowAttrs + , rowFilter = \_ _ -> True } @@ -427,9 +429,17 @@ view (Config { toId, toMsg, columns, customizations }) state data = thead = Html.thead theadDetails.attributes theadDetails.children + filterSortedData ( sortIndex, data ) = + if customizations.rowFilter sortIndex data then + Just data + else + Nothing + tbody = Keyed.node "tbody" customizations.tbodyAttrs <| - List.map (viewRow toId columns customizations.rowAttrs) sortedData + List.map (viewRow toId columns customizations.rowAttrs) <| + List.filterMap filterSortedData <| + List.indexedMap (\i -> (,) i) sortedData withFoot = case customizations.tfoot of