Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.1.0
-
None
-
Mac OS 10.8
-
c47c502e794f7ae37c516a1db123139d9dc1270d
Description
I have a TableView that allows the number columns and roles to change dynamically. When I update the columns, the TableView's column headers update correctly, but the cells in the table are empty. They should be filled with data from the model instead of being empty.
A workaround to this bug is to set the TableView's model to null, and then set the model back to it's original value. Then the model's data shows up in the table view.
Item { TableView { id: tableView anchors.fill: parent // model: csvPreviewModelId /** This populates the table columns with data dynamically */ function updateColumns() { tableView.model = null //WORKAROUND var columns = csvPreviewModelId.columnNames; var columnObjects = []; for(var i in columns) { var columnName = columns[i] var newColumn = tableViewColumnComponent.createObject(tableView, {role: columnName, title: columnName}) columnObjects.push(newColumn) } tableView.columns = columnObjects tableView.model = csvPreviewModelId //WORKAROUND } Component.onCompleted: { tableView.updateColumns() } } Connections { target: csvPreviewModelId onColumnNamesChanged: tableView.updateColumns() } Component { id: tableViewColumnComponent TableViewColumn { } } }