Kars
Kars

Reputation: 917

How to bind a property of a property to column in Tornado TableView?

I'm trying to bind a property of a property of a class to a column in TornadoFX TableView. It is only letting me bind the property itself, which is an instance of a class. This shows the instance ID of the class (model.Address@2fe90a0b) and not the property that i want to display. Is there a way to bind properties of a property to a column in TableView?

val people = mutableListOf<Person>().observable()

tableview(people) { 
    id="ResultTable"
    readonlyColumn("First Name",Person::firstName)
    readonlyColumn("Last Name",Person::lastName)
    readonlyColumn("Email Address",Person::email)
    readonlyColumn("Street", Person::address) // this property is a class
    columnResizePolicy = SmartResize.POLICY
    isEditable = true
}

I want to bind the property Address.street to the column "Street"

Upvotes: 1

Views: 245

Answers (1)

Edvin Syse
Edvin Syse

Reputation: 7297

Yes, that's possible, and you have several options. One is to simply override what is shown in the column:

readonlyColumn("Street", Person::address).cellFormat {
    text = it.street
}

The other is to supply a function to extract the property. However, since it seems like you've opted to not follow best practices and use observable properties in your domain objects, you need to convert your String value into an observable property when you return it:

column<Person, String>("Street") {
    SimpleStringProperty(it.value.address.street) 
}

Upvotes: 2

Related Questions