If you are attempting to implement column of check boxes mimicing selection column on the right instead having the default one on the left side the code would be something like this:
Tatu Lund:
If you are attempting to implement column of check boxes mimicing selection column on the right instead having the default one on the left side the code would be something like this:
I hoped the solution would answer another question but it doesn’t.
Since the grid is build out of two diffrent classes I have no clue how to get the Values from the selected row.
Something like adding a new Button on the page which pushs the value in the first column of an selected row to the page:
Button button = new Button();
add(button);
button.addClickListener(e -> {
//Some code to get the the data from the first column of the selected row
add(/*the data*/);
});
You don’t have to access the Component in the grid-row, but instead you can access the value of the selected item. They should always match, because the component should only show the value of the column-property of the item anyways.
As an example, let’s assume you have a Grid<Person> and Person has a firstName. If you want to “push the firstName of a selected row to the page”, then you don’t read the value from the TextField Component inside the grid, but you read the value from the actual Person item.
button.addCLickListener(e -> {
// retrieve firstName of selected row
Person selectedPerson = grid.getSelectedItems().iterator().next(); // not sure if this line works, may need testing
if(selectedPerson != null){
// add the data
add new Div(selectedPerson.getFirstName());
} else {
// no selection
}
}
You don’t have to access the Component in the grid-row, but instead you can access the value of the selected item. They should always match, because the component should only show the value of the column-property of the item anyways.
As an example, let’s assume you have a Grid<Person> and Person has a firstName property. If you want to “push the firstName of a selected row to the page”, then you don’t read the value from the TextField Component (or whatever component it may be) inside the grid, but you read the value from the actual Person item.
button.addCLickListener(e -> {
// retrieve firstName of selected row
Person selectedPerson = grid.getSelectedItems().iterator().next(); // not sure if this line works, may need testing
if(selectedPerson != null){
// add the data
add new Div(selectedPerson.getFirstName());
} else {
// no selection
}
}