Orasund / elm-ui-widgets

Collection of reusable views for elm-ui.
https://orasund.github.io/elm-ui-widgets/
BSD 3-Clause "New" or "Revised" License
85 stars 11 forks source link

Allow arbitrary Elements in table columns #84

Closed lukasturcani closed 2 years ago

lukasturcani commented 2 years ago

I would like to be able to place buttons into the rows of the table. Something like

+-----------------+----------------+----------------+
|   column 1      |    column 2    |                |
+-----------------+----------------+----------------+
|      one        |      two       | <button>       |
+-----------------+----------------+----------------+
|      three      |      four      | <switch>       |
+-----------------+----------------+----------------+

For that I think that ColumnType and Column need to have a second type variable for msg.

-type ColumnType a
+type ColumnType a msg
     = StringColumn { value : a -> String, toString : String -> String }
     | IntColumn { value : a -> Int, toString : Int -> String }
     | FloatColumn { value : a -> Float, toString : Float -> String }
+    | ElementColumn { value : a -> Element msg }
     | UnsortableColumn (a -> String)

-type Column a
+type Column a msg
     = Column
         { title : String
-        , content : ColumnType a
+        , content : ColumnType a msg
         , width : Length
         }
Orasund commented 2 years ago

Hi. Yes you are right. This should be the correct way to fix this.

Could you please open a PR?

Lukas Turcani @.***> schrieb am Fr., 17. Dez. 2021, 21:27:

I would like to be able to place buttons into the rows of the table. Something like

+-----------------+----------------+----------------+ | column 1 | column 2 | | +-----------------+----------------+----------------+ | one | two |

lukasturcani commented 2 years ago

Will do!

Orasund commented 2 years ago

Thanks a lot ;) You were a big help!