kishanov / re-frame-datatable

DataTable component for re-frame library
https://kishanov.github.io/re-frame-datatable/
Eclipse Public License 1.0
103 stars 16 forks source link

How to open a panel on click per row? #16

Open raymcdermott opened 6 years ago

raymcdermott commented 6 years ago

The item selection as it is explained seems perfect for allowing actions on several rows.

How can I attach a click handler to each row individually?

In my case, I would like to show a model panel when the user clicks on an item. But I never need a list of selected items.

Perhaps I'm missing something obvious :-/

raymcdermott commented 6 years ago

As a hack I add this to the end of the table definition

(when (not (empty? @selected-item))
                  (my-modal @selected-item))

It's still not quite what I want as I would rather have the row itself to be clickable rather than via a selection control.

kishanov commented 6 years ago

It is not supported right now. I think the proper design approach would be to add an :on-row-select that accepts an event vector and conj`s selected-indexes as the last item in event vector.

Let me experiment with this idea, and if it works as expected - I'll release new version during Thanksgiving break

raymcdermott commented 6 years ago

Is the design working out as expected?

raymcdermott commented 6 years ago

I have made a nicer workaround where I create a "View" button for each row which :on-click dispatches the index of the current row of the table data to an event. It's horribly inelegant and would not scale well but does the job.

thevermeer commented 6 years ago

@kishanov - I see this as a major feature of re-frame-datatable. In my mind, I should be able to assign as event to tr/row click and that event accepts the row data, as bare minimum. Regardless, the developer ought to be able to trigger events on row click without row selection per se. As @raymcdermott has pointed to, being able to summon an external modal, for instance, would greatly broaden the use of this component.

smahood commented 6 years ago

I've just implemented this in a fork at https://github.com/smahood/re-frame-datatable/commit/ae0feca788c53e2cb5c7f0f2d83b7ad6412b95b3

If you want an actual PR let me know - it was a super simple change to get it to work the way I wanted, which I think means you've done something really good in designing this library! (Ignore the project.clj change - I'm using lein checkouts and that was the easiest (and laziest) way to do it.)