livebook-dev / kino

Client-driven interactive widgets for Livebook
Apache License 2.0
361 stars 60 forks source link

Add a :formatter option to Kino.DataTable.new/2 #441

Closed kipcole9 closed 3 months ago

kipcole9 commented 3 months ago

See the discusssion in #440.

Adds a :formatter option to Kino.DataTable.new/2 which is a 2-arity function passed the key (column name) and cell value.

The special key :__header__ is passed when formatting the column headings.

jonatanklosko commented 3 months ago

Hey @kipcole9! I like the idea, just a small note on the API and we can ship it :D

jonatanklosko commented 3 months ago

Ah and as for tests, please add one in test/kino/data_table_test.exs. For example here:

https://github.com/livebook-dev/kino/blob/93d042a7c72c77584004644391a52c7d2ef6f8ee/test/kino/data_table_test.exs#L249-L261

The data: [...] carries the already formatted values.

kipcole9 commented 3 months ago

@jonatanklosko, thanks for the review and great suggestions. I've made the requested changes, tests are passing. Now I just need to add a new test as you proposed.

kipcole9 commented 3 months ago

Test case added so I think this is now ready for the next review.

jonatanklosko commented 3 months ago

@kipcole9 perfect, last two nitpicks!

kipcole9 commented 3 months ago

Fixed as requested. Let me know if there's anything else?