I have a DataGrid, and I set a column with TextButtonCell.
If nothing is selected, everything is fine.
But once I select a row, the text on the button disappears.
How can I stop the text on the button disappearing?
Edit
Below is the code I created this button column:
Column<Publication, String> buttonColumn =
new Column<Publication, String>(new TextButtonCell()) {
#Override
public String getValue(Publication pub) {
((TextButtonCell)getCell()).setEnabled(pub.isPublishable());
return "Publish";
}
};
buttonColumn.setFieldUpdater(new FieldUpdater<Publication, String>() {
#Override
public void update(int index, Publication pub, String value) {
publish(pub);
}
});
pubDG.addColumn(buttonColumn);
Do not use selection model if possible. May be it will solve your problem
If you wat to use selection model then override the css to change the color of text of selected row then you will be able to see the text of text button.
Related
Requirement : Mask the datepicker on blur / form submit.
I was able to get the masking done onBlur with forceparse set to false but i'm unable to navigate to the next month/year in the datepicker maybe because i'm overriding the DOM handlers.
dob.setForceParse(false);
dob.addDomHandler(new BlurHandler() {
#Override
public void onBlur(BlurEvent event) {
dob.getTextBox().setText(**masked value**);
}
}, BlurEvent.getType());
dob.addDomHandler(new FocusHandler() {
#Override
public void onFocus(FocusEvent event) {
dob.setValue(**unmasked value**);
}
}, FocusEvent.getType());
I am unable to use ChangeDateHandler, since it automatically assumes "1/1/19" as "1/1/1900" and masks the text mid-way of text enter. Is there any other way i can handle this?
If you are having problems with DatePicker's TextBox you can just hide it and use any other Widget instead.
TextBox is basically used to show the DatePicker when is focused, to show selected date and to enter the date manually.
Here is an example code how to use your own TextBox with DatePicker (I use VerticalPanel to show DatePicker just below the TextBox):
VerticalPanel container = new VerticalPanel();
final DatePicker dob = new DatePicker();
// hide DatePicker's TextBox
dob.getTextBox().getElement().getStyle().setDisplay(Display.NONE);
final TextBox box = new TextBox();
box.addFocusHandler(new FocusHandler() {
#Override
public void onFocus(FocusEvent event) {
dob.show();
box.setText("**unmasked value**");
}
});
dob.addHideHandler(new HideHandler() {
#Override
public void onHide(HideEvent hideEvent) {
box.setText("**masked value**");
}
});
dob.addChangeDateHandler(new ChangeDateHandler() {
#Override
public void onChangeDate(ChangeDateEvent evt) {
Window.alert("ChangeDateEvent");
}
});
container.add(box);
container.add(dob);
Just notice, that you need to call dob.show() when TextBox is focused. I also use DatePicker's HideHandler instead of TextBox's BlurHandler to show masked value but you may change it as you wish.
If you want to change the way of parsing dates like "1/1/19", now you can add your own parser to the TextBox.
I am working on GXT 2.5.5
I have desinged a GRID in a project
In one column of the grid i have render a composite
It looks like this
This Choose evaluation column is Composite which is rendered in the Grid.
public class Evaluation extends Composite {
private RadioGroup rdgrpEvaluation;
private Radio radio_1;
// More radion buttons
private Radio radio_10;
}
All the radio_x.setValue(true) in the grid are set from the Model
int key = model.get("radioEvaluation");
switch (key) {
case 1:
evaluation.getRadio_1().setValue(true);
break;// more similar code
Now i want that when I click on radio button, the value of the Evalution column should also change.
Can some body help ?
I think that simplest way is call refresh whole table after selecting some button:
grid.getView().refresh(false);
But you also need to update your model.
When You click on radio button you may set value to your model like^
data.setEvalueation(int selectedRadio);
Or You can create specified ValueProvider to Evaluation column
ColumnConfig<Data,String> evaluationColumn = new ColumnConfig<Data, String>(new ValueProvider<Data>() {
#Override
public String getValue(Data o) {
String value = o.getRadioColumnValue();
return value;
}
#Override
public void setValue(Data o, Data o2) {
}
#Override
public String getPath() {
return "evaluation";
}
});
GXT3 - Grid: Adding a column with a button to modify row in Editable Grid
In the example the line is editable automatically when line is selected.
http://www.sencha.com/examples/#Exam...oweditablegrid
I want the line to be changed when I click on the edit button that would appear in a popup.
TextButtonCell button = new TextButtonCell();
button.addSelectHandler(new SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
Context c = event.getContext();
Info.display("Event", "Call the popup here.");
}
});
nameColumn.setCell(button);
There is a way do get this?
Thanks in advance for your help.
First of all you have yo create a column with TextBoxCell which may you already created.
Then you have to disable default onclick editable behavior of grid.
For that as per Sencha example's file RowEditingGridExample.java you can override onClick event and prevent to fire default code.
public class RowEditingGridExample extends AbstractGridEditingExample {
#Override
protected GridEditing<Plant> createGridEditing(Grid<Plant> editableGrid) {
return new GridRowEditing<Plant>(editableGrid){
#Override
protected void onClick(ClickEvent event) {
}
};
}
}
And when you click on textBoxCell click handler you can start editing manually.
TextButtonCell button = new TextButtonCell();
button.addSelectHandler(new SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
Context c = event.getContext();
//Here you can pass a new GridCell like with proper cell index and row index.
GridCell cell = new GridCell(getRowIndex(), getCellIndex());
editing.startEditng(cell);
}
});
nameColumn.setCell(button);
If you want to appear row editor in separate popup you have to design it manually.
Hello I have a Contact class with informations which i show in a CellTable.
The CellTable has a DataListProvider, MultiSelectionModel and KeyProvider
which checks the id of the Contact.
DataListProvider and CellTable have the same KeyProvider.
if i only select/deselect the items in the CellTable and show them in a TextBox ists working fine. But the when i change the value of the Contact item in the TextBox(Contact instance) and try to deselect the item the selectionmodel says its still selected?
I tried with clear() but its still selected!
GWT 2.5 / FireFox
ProvidesKey<Contact> keyProvider = new ProvidesKey<Contact>(){
#Override
public Object getKey(Contact item) {
return item.getIdContact();
}
};
public MyCellTable(boolean canLoad, Integer pagesize, ProvidesKey<T> keyProvider) {
super(-1, resource, keyProvider);
selectionModel = new MultiSelectionModel<T>();
selectionModel .addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
#Override
public void onSelectionChange(SelectionChangeEvent event) {
selectionChange();
}
});
dataProvider = new ListDataProvider<T>(keyProvider);
dataProvider.addDataDisplay(this);
}
in the selection event i call
protected void selectionChange(){
Contact c = grid.getGrid().getSelectedItem();
if(c != null){
cpForm.enable();
cpForm.clear();
form.bind(c); // Formular which updates the selected instance
cpForm.add(form);
}else{
cpForm.disable(noseletionText);
}
}
i have no ValueUpdater
when i select an item i generate a formular and if i change something i call:
#Override
public void save() {
super.save();
ContactServiceStore.get().updateContact(manager.getBean(),
new MyAsyncCallback<Void>() {
#Override
public void onSuccess(Void result) {
onchange();
}
});
}
i if call the method without changes on the contact its still working and i can deselect but when i change the name or something else i cant select other items or deselect the current item!
You're not actually using your ProvidesKeys in your MultiSelectionModel. You need to create your MultiSelectionModel like so:
MultiSelectionModel<T> selectionModel = new MultiSelectionModel<T>(keyProvider);
If you don't supply the MultiSelectionModel with a ProvidesKey it will use the actual object as a key.
Make sure you also add the MultiSelectionModel to the table:
cellTable.setSelectionModel(selectionModel);
The reason selectionModel.clear() wasn't working was because selectionModel was not set to the table.
I have a user form with a lot of gwt listbox. The form is like an excel form with named list.
It's ugly and the arrows take place.
I would like the cells were like in excel. The arrow appears only when you click in the cell.
I start to program my own widget with a textbox and a listbox embedded into a DeckPanel, switching when you click on the textbox or when the value change. But with this solution, it is necessary to click again to open the listbox.
Now, it will be great, if when you click on the textbox, the listbox will be displayed already open.
In the code below, I try to do this into the method onClick wih this line:
DomEvent.fireNativeEvent(event.getNativeEvent(), listBox);
But it has no effects.
public class CustomListBox extends Composite implements ClickHandler,
ChangeHandler, HasChangeHandlers {
private final StringListBox listBox;
private final TextBox textBox;
private final DeckPanel panel;
public CustomListBox() {
textBox = new TextBox();
textBox.addClickHandler(this);
textBox.setReadOnly(true);
listBox = new StringListBox();
listBox.addChangeHandler(this);
panel = new DeckPanel();
panel.add(textBox);
panel.add(listBox);
panel.showWidget(0);
// All composites must call initWidget() in their constructors.
initWidget(panel);
}
#Override
public void onClick(ClickEvent event) {
Object sender = event.getSource();
if (sender == textBox) {
panel.showWidget(1);
DomEvent.fireNativeEvent(event.getNativeEvent(), listBox);
}
}
public void addItem(String item) {
listBox.addItem(item);
}
public int getSelectedIndex() {
return listBox.getSelectedIndex();
}
public String getItemText(int selectedIndex) {
return listBox.getItemText(selectedIndex);
}
#Override
public HandlerRegistration addChangeHandler(ChangeHandler handler) {
return listBox.addChangeHandler(handler);
}
#Override
public void onChange(ChangeEvent event) {
Object sender = event.getSource();
if (sender == listBox) {
textBox.setText(getItemText(getSelectedIndex()));
panel.showWidget(0);
}
}
}
Since you are already programming your own widget, why don't you go all the way. Don't swap out the text box for a list box widget. Instead of a textbox use a label. Add an arrow to your label background when you mouse over, then use a popupPanel for the list itself. In the popupPanel you can make the list items whatever you like, just make sure when you click on it, it sets the text in your original label.