I have a tableview with one textboxcolumn and 7 checkbox columns.
This table will eventually be filled with data, and at some later point i have to remove one of the columns somewhere in the middle. What happens with the array associated with the table? How should i proprtly handle this? How would you do it? Please be clear in your answer since i am a beginner!
Have you learned how to provide data to the table view? I suggest getting that working before you try to solve this problem.
There are two ways to get data to the table view: a table view data source and Cocoa Bindings.
If you use a data source, you'll need to write -tableView:objectValueForTableColumn:row: so that it works correctly before or after the column is removed. One way to do this is to base that code on the column's identifier instead of its index. The identifier is a value you set on the column in your nib (look for Identifier). This is the same technique you can use to provide the correct data to reordered columns.
NSString *identifier = [column identifier];
if ([identifier isEqualToString:#"firstField"]) {
return ...
} else if ([identifier isEqualToString:#"secondField"]) {
return ...
}
If you use Cocoa Bindings, you can just remove a column and the other columns will keep working.
If you're using an array or an array controller, in neither case will anything automatically happen to the array when you remove a column.
Related
I have a abstract table (table or treetable view does not matter) view which have lots of column. But not all columns are visible at the same time. Now what i want to do, when i export the table contents to pdf/excel read each row data but actually in javafx we can not get row and cell data directly. For this we must use row/cell factory. But in this case this factory is called only when we add data to the table. I can read table data model for each row but in this case i must chek which columns are visible and invisible and which data model used always, and call the required method of the data model. Doing this required lots of code lines because as mentioned i have lots of column and nested column and also different data models. So during exporting to check all of these required lots of code line. But if i can read the row and cells of row i do't need to check invisible row and data model. Just read current row and data of cell. So my question is how can i solve this issued? Do you have any suggestion?
Any suggestion?
finally I solved this problem. Thanks for java documentation. I post some code snippet so who needs can use. For reading cell value on (row,column) intersection on TreeTableView
int rowIndex = treeTableView.getRow(treeRowItem);
for(int i=0;i<treeTable.getColumns();i++){
TreeTableColumn ttc = treeTable.getColumns().get(i);
String value = ttc.getCellData(rowIndex).toString();
}
you can also use the same logic on TableView
I am new to handsontable.
My handsontable rows are readonly.
I wanted to remove all rows of handsontable on a button click.
Please help me.
Do update with empty dataset:
handsontableInstance.updateSettings({
data : []
});
This removes all rows (and leave header if there is some).
There are many ways to "remove" all rows. For example, one, and the easiest, would be to empty your data array. So say that you initialized your HOT instance with the data field as array dataArray. Your button would only need do:
$("#buttonId").click(function() { dataArray = [];})
That would be the easiest way but of course you'd be bypassing HOT. This means that if your application gets more complex and you rely on handlers such as afterRemoveRow, then this method will bypass them. In this latter case, you'd want to use the hot.alter() method as follows:
hot.alter('remove_row', 0); // would remove the row at index 0;
With this I am assuming you know how to use a for loop that could iterate through all rows and remove them, one by one. An expensive operation but it would ensure all the proper handlers get called.
tableInstance.clear()
Clears the data from the table (the table settings remain intact).
refer to the
doc
everyone!
How to populate first column of nstableview with strings from array and the second column with strings from another array in dependence of selection in first column?
For example, look at the iTunes window, where the first column is selected playlist, and the second, a list of songs.
I could not find something like this on the internet.
I would be very grateful for the help.
This is little info about my model:
array with content for tableView populated with instances of NSObject sublass. This instances have three properties, to properties - NSString object, and last property an NSArray object with another strings. First and second properties used to populate first column, and i don't know how to populate sec on column with third property (strings from another array).
How to do this with bindings?
First of all: You do not populate columns, but rows. But reading your whole question, it seems to be that you understood this.
The solution is, that you do this with nested arrays and two table views:
Bindings:
A. The first table view gets the array of instances via an array controller that are on the top level of your model. Let's say "list of playlists". This array builds the rows for that table view with probably one column. The first column is bound to a property, likely "title".
playlistsArrayController.contentArray: somewhere.playlists
viewColumn.content: playlistsArrayController.arrangedObjects.title
B. Then you have a second table view with a second array controller. This is bound to the selection of the first one (playlists) and the property that contains the subentries, i. e. songs. This second array builds the rows of the second table view. Typically you have more columns there, every bound to a specific property ("title", "length", …)
songsArrayController.contentArray: playlistsArrayController.selection.songs
viewColumn1.content: songslistsArrayController.arrangedObjects.title
viewColumn2.content: songslistsArrayController.arrangedObjects.length
Both bindings are typed in Safari only for explanation.
I am using a NSArrayController to display the records in a NSTableView. I am reading back a selected record using [recordArray objectAtIndex:[tableView selectedRow]]. This is working fine when I don't click any of the headers in the table to sort the data. When I click a header to sort the data, the data is sorted on the screen but not in my recordArray and the order of my recordArray does not match the order of the data in the table view anymore.
My recordArray is of type NSMutableArray and contains records of type BrowserRecord. BrowserRecord contains the fields name and type (both NSString and readwrite).
I've followed all the guidelines and examples found in books and on the internet and I find it very confusing that it doesn't work for me (my previous version of the code without core-data was working fine). I must be doing something very strange. Hope that someone can point me out into the right direction.
Your array controller is managing the sorted contents. Ask it for its -arrangedObjects.
I'm pretty new to Core Data and managed to get the NSTableView to show my Core Data values. The entity that the table uses is Emotes that have the two properties, Emote (string) and Usage (integer 16)
When a user selects a item, it will allow a person to copy that emote to clipboard. In order to do that, I need to get the ManagedObject of the selected row and send the Emote value in the object to the clipboard. I got the clipboard part, but stuck on the part in retrieving the data of the selected row from the data source.
What is the easiest way in getting the value of the selected row?
What is the easiest way in getting the value of the selected row?
The easiest way is to query the NSArrayController for
- (NSArray *)selectedObjects
You don't have to worry about what rows are selected; the table view will tell you what rows to copy by sending you (the data source) a tableView:writeRowsWithIndexes:toPasteboard: message.
Whatever you do in your implementation of tableView:objectValueForTableColumn:row:, you'll implement that method pretty much the same way, except that instead of retrieving and returning a single column value, you'll write (or at least promise) all of them at once, in whatever formats make sense, to the pasteboard.