简体   繁体   中英

tornadofx EventBus expand table row using tableview object

Background:
Suppose I have multiple fragments of a single table in a view , each with a rowExpander.

Expected Behaviour:
If in one table fragment I expand a row, other fragments same indexed row should get expanded. Same for collapse

My Progress:
Sample Fragment:

tableview(dataset) {
                column("First Name", Person::firstNameProperty)
                column("Last Name", Person::lastNameProperty)
                rowExpander(true) {
                    selectedData.item?.apply {
                        fire(ExpandDataEvent(dataset.indexOf(this)))
                    }
                    column("Mobile Nos.", Person::mobileNumProperty)
                    column("Email Ids", Person::emailIdProperty)
                }
                bindSelected(selectedData)
                subscribe<ExpandDataEvent> { event ->
                    selectionModel.select(event.index)
                }
            }

Event Class:

class ExpandDataEvent(val index: Int) : FXEvent()

What I understand from "subscribe" is that it gets called when an event is fired (currently I am firing the event whenever the user expands the row by either double-click/clicking the plus sign); and since the subscribe is placed inside tableview, it gets called for all the table fragments present (which is what I want). But in the subscribe method I am doing a selectionModel.select(event.index) which only selects the corresponding index row. I want to expand the row (preferably by using the selectionModel)

Question 2:
Is it possible to remove the plus sign column? For rowExpand, if I have set expandOnDoubleClick to true, I dont want the plus sign column in my tableview.

The rowExpander builder returns the actual ExpanderColumn which is basically a normal TableColumn . Save a reference to the expander so that you can operate on it later:

val expander = rowExpander(true) { ... }

Directly below, you can now hide the expander column:

expander.isVisible = false

Now it's easy to toggle the expanded state of a specific row from the event subscriber as well:

subscribe<ExpandDataEvent> { event ->
    expander.toggleExpanded(event.index)
    selectionModel.select(event.index)
}

You might want to double check that you don't toggle the expander for the tableview that fired the event, so consider including the event source in your event and discriminate on that in the subscriber.

I will investigate if we can add a visible boolean parameter to the rowExpander builder function so you don't need to call isVisible manually :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM