I have got a QTableView with data in it. What is the simplest way to add a row?
Thanks!
As you use som YourModel to show it in YourTableView (QTableView) should do like this:
YourModel->insertRow(YourModel->rowCount(QModelIndex()));
// paste some data to new row
update of model causes update of View
QTableView is model based if you don't know what model is then I suggest you read here.
Use QTableWidget instead is much easier for a beginner and you can add a row just like this
ui->tableWidget->insertRow(0);
Related
Is there a way to filter table columns data as there is a way in excel to filter.
Filtering manually require a very long code if data is huge. So trying to find an easy way. Please suggest something.
I went through the following link for the same but need an easier and efficient approach.
http://code.makery.ch/blog/javafx-8-tableview-sorting-filtering/
There's no built-in filter capability for TableViews like Excel.
I've written a library that provides the GUI filters, but you'll still need to programmatically apply the results to filter your dataset:
https://code.google.com/p/javafx-filterable-table-columns/
https://github.com/jhsheets/javafx-filterable-table-columns
I wrote an extension for that use case:
https://github.com/maimArt/TableFilterFX
The implementation of the filter is quite easy. You wrap your TableView with the TableFilter and add the columns that should be filterd by tableFilter.filterColumn(TableColumn column)
1 Build your TableView like usual by code or fxml
TableView<Pojo> table = new TableView<>();
table.getItems().addAll(pojoList);
TableColumn<Pojo, String> columnA = new TableColumn<>("ColA");
TableColumn<Pojo, String> columnB = new TableColumn<>("ColB");
table.getColumns().add(columnA);
table.getColumns().add(columnB);
2 After that apply the filter
TableFilter<Pojo> tableFilter = new TableFilter<>(table);
tableFilter.filterColumn(columnA);
tableFilter.filterColumn(columnB);
I have seen most of the examples of dc.js which filters the data using brushes. How should i filter the data using the row element selected from datatable??
I am not sure of exact solution but some workaround may be done as
dimension.filter(value)
where value updated onclick? Am I going in right direction or is there a better way?
Edit 1
If i draw a row chart of the same thing with the then I don't have to handle onlcick event or anything but for datatable why is it comparatively so much complecated?
That should work. You will have to trigger the redraw events to the charts know about the change.
yes I put a onclick="function(value)" button.
and
window.function(value){
table.dimension(dimension);
table.filter(value);
table.render();
}
PS: I am not proficient in dc.js so this method might not be a optimal solution
Using QTableView I would like to be able to select multiple cells and change all selected cells at once. How I can do it?
I'm not sure exactly what you mean by "changing" the selected cells (content, formatting, something else?) but I think QTableView::selectedIndexes() (or QTableView::selectionModel() if you need more power) is going to help out. You can loop through the returned indexes and update your underlying model.
If you are using a QSortFilterProxyModel you will have to use the QSortFilterProxyModel::mapFromSource() and related methods to map from the selected cells on your table view to the actual model indexes.
Ok so I have drop down list connected to a datasource, and I need to change 2 or 3 of the values before they are displayed and I'm just having trouble figuring out what to do. I'm assuming I setup some kind of loop to check the values, but thats all I can figure. Does anybody have any general suggestions or resources they know that I can look up? Thanks.
You need to do your processing before you bind the datasource. So for example, create a dataset of results or arraylist, process the results changing your values and then bind to your dataset/arraylist.
You'll need to be more specific about what you are binding to and how you want to process for me to be more specific..
See link at http://www.c-sharpcorner.com/uploadfile/sd_patel/dropdownlistbox11222005064123am/dropdownlistbox.aspx
I have an table view showed
part description, quantity, price
And I have a Model/View using this code
model = new QSqlRelationalTableModel(this);
model->setTable("parts");
model->setRelation(3,QSqlRelation("part_tbl","part_id","part_desc"));
model->select();
ui->tableView->setModel(model);
I need to add a new column that shows quantity * price in the table view. It's important to know I'm using QsqlRelationalTableModel
Help is appreciated, Thanks in advance
I think your best bet for handling this is to make either a model that inherits QSqlRelationalTableModel, or one that acts as a proxy (and contains a member for the model). Your new model will add the extra column, and when the data is requested for that column, use the data from the other columns to compute what is required.