Cannot uncheck checkbox in smartgwt listgrid - gwt

I'm breaking my head since a whole day now but cannot find a solution, I hope someone can help me.
I'm trying to create a simple SmartGWT ListGrid with checkboxes and for some reason I can only check checkboxes but not uncheck them.
Once the checkbok is checked there is no way to uncheck it.
Below the code I'm using to create the grid.
Here I first instantiate the grid that is populated later with a call to the server.
Any idea of what I'm doing wrong? Anything wrong with the initialisation maybe?
Thanks in advance!!
[...]
ListGrid hotelsGrid = new ListGrid();
hotelsGrid.enableHiliting(false);
hotelsGrid.setCanSort(false);
hotelsGrid.setCanResizeFields(false);
hotelsGrid.setShowHeader(false);
hotelsGrid.setAutoFitData(Autofit.BOTH);
hotelsGrid.setStyleName("selectGrid");
hotelsGrid.setCanEdit(false);
hotelsGrid.setShowHover(false);
hotelsGrid.setShowRollOver(false);
hotelsGrid.setShowSelectedStyle(false);
hotelsGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
[...]
private void initGrid(String[] sParams){
ListGridField flagField = new ListGridField("flagField", "Status", 40);
flagField.setAlign(Alignment.CENTER);
flagField.setType(ListGridFieldType.IMAGE);
flagField.setImageURLPrefix("flags/");
flagField.setImageURLSuffix(".png");
ListGridField textField = new ListGridField("textField", "Meaning");
hotelsGrid.setFields(flagField, textField);
hotelsGrid.setData(getSelectRecords(sParams));
}

It's not clear how your code sample above is related to a clickable checkbox - your code doesn't make any attempt to create a field with checkboxes??
All you need to do to get a clickable checkbox is declare a field of type "boolean" and setCanToggle(true). setCanToggle(true) allows it to be toggled with one click without needing to have editing enabled for any other fields.

Related

GWT: Multi Selection model does not update the celltable status in some cases

I am using the GWT MultiSelectionModel within a CellTable in which I have a checkbox in one column and a widget in the other column. I have added handlers to update the selection status based on user clicks. If the user clicks on any part of either columns when the cell is selected, the status gets updated correctly and the cell turns white from light blue. Howvever, If the user clicks on the check box and the cell is selected, the check box gets unchecked but the cell is still blue. Even more strange: This issue does not happen if I have a few breakpoints before the status update code is executed.
In all other cases, the cell state and the checkbox state gets updated correctly. Note that I am not using the ProvidesKeys interface since the object do not change.
Can anyone help me with this? Thanks for your help.
Have you tried using a CheckBoxCell for your checkbox column and, specifically, the CheckboxCell(boolean dependsOnSelection, boolean handlesSelection) constructor (by passing true to both params)?
I've got almost the same problem when I use MultiSelectionModel. What's my walkaround is to see the checkbox's column as a special one and then to deal with it manually. Say:
myDataGrid.addCellPreviewHandler(
#Override
public void onCellPreview(final CellPreviewEvent<MyCellData> event){
if("click".equals(event.getNativeEvent().getType()) && 0 != event.getColumn()){
doWhatYouWant();
}
}
)

How to add a custom selection Handler to a celltable

I want to add a special selection model to the celltable. Basically the function i want to have is to select a row on the table which is located on left side, a corresponding form will pop up on the right side.
I know so many people will use the singleSelectionModel with SelectionChangeHandler.
But there is problem with this method.
For example, if I select row 1 on the table. the form pop up. I close the form by clicking the close-button. Later then, I select the row 1 again, the event is not fired, because it is SelectionChangeHandler. I have to select other row before doing this. This is no good.
So I think there are a few ways to do this:
Make the row deselected right after I select the row.
Use click handler to fire the event ( to pop up the form)
Use other selection model with other selection handler to do this. (I have no ideas about this though)
So my questions are,
Does anyone know what kind of other selection handler I can use for this.
If I use the click handler on celltable, will there be any problem?
I just want to learn more about this. So any ideas will be welcome.
Thanks a lot.
Best Regards.
Use NoSelectionModel. It won't update the table view after the row is selected. That is, even if the same row is selected, the change event is fired.
//Here 'Contact' is the datatype of the record
final NoSelectionModel<Contact> selModel = new NoSelectionModel<Contact>();
selModel.addSelectionChangeHandler(new Handler() {
#Override
public void onSelectionChange(SelectionChangeEvent event) {
Contact clickedObject = selModel.getLastSelectedObject();
GWT.log("Selected " + clickedObject.name);
}
});
table.setSelectionModel(selModel);
I have using cell table in my each project. The better way to just deselect row manually as u mention. and make change css such as selected cell table's row look not changed after selection.

GXT Grid Checkbox Header Select/Unselect All

Working with GXT and using a checkbox selection model. I notice that when every row is checked, the checkbox header will also be checked, but the checkbox header has no functionality of its own.
How can I tell the checkbox header to select/unselect all checker rows when clicked?
Thanks for the help!
You need to add the selection model as a plugin to the grid.
grid.addPlugin(sm);
You will need to set the selection model on the grid directly.
identityProvider = new IdentityValueProvider<DataModelProxy>();
checkboxSelectionModel = new CheckBoxSelectionModel<DataModelProxy>(identityProvider);
checkboxSelectionModel.setSelectionMode(SelectionMode.MULTI);
grid.setSelectionModel(checkboxSelectionModel);
where DataModel is your datamodel and proxy of this model.

Dynamcially adding panels based on DropdownChoice selection

am a newbie to wicket and am experimenting few things with it, like, I have four panel but one only should be added based on the selection made in the DropdownChoice component.
i tried to add panels using onSelectChange() method, but it doesn't work. can any one please help me out with proper sample code.
I give you an example for this problem. Hope it helps.
DropDownChoice dropDown = new DropDownChoice(...........);
AjaxFormComponentUpdatingBehavior behavior = new AjaxFormComponentUpdatingBehavior(
"onchange") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
//you should write here the logic that
// replaces the panel, something like: content.addOrReplace(panel)
target.addComponent(form);
}
};
dropDown.add(behavior);
So that's all, you have to use AjaxFormComponentUpdatingBehavior to handle onchange event. If the dropdown menu not a requirement, you can use tabbedpanel. Here you can find the sample code: wicket tabbed panel

GWT TextBox widget

I have a well populated Object which has properties like color,size,weight etc.
I need to get these object properties and place them in a TextBox.
So i want to do something like
`textBox.getLine1.setText(Object.getColor());
textBox.getLine2.setText(Object.getWeight());`
That is i need a textBox in which i can edit individual lines.
I am planning to have a widget which has a FlexTable inside the TextBox but i am not sure how to work on it.
Can someone please help me on this?
Thanks
Probably you're looking for the RichTextArea widget
You can check the documentation here: RichTextArea
And an old, but nice tutorial here: Tutorial
I did something similar: I needed to let user select one or several text rows and let each row be clickable to perform an action.
So I used a VerticalPanel with Labels.
VerticalPanel labelPanel = new VerticalPanel();
For a given index Label:
Label selectedLabel = (Label) labelPanel.getWidget(index);
DOM.setElementAttribute(selectedLabel.getElement(), "id", "label-selected");
CSS code as you wish!
If you must use a TextArea, which is a standard <input type="text"> element, you would have to find line breaks and create a Selection, and then replace it with whatever you want. You could also read the entire text, change it, and then update the entire TextArea value again.
I would recommend splitting your widget into multiple single line TextBoxes.