I have a ListGrid which I want to use to display data coming from one of these services. I wanted also to be able to create, modify and delete new records.
So:
1 ListGrid + 3 buttons for create, modify and delete + 1 button to validate.
.When the edit is finished I use the validate button to trigger EditComplete event with the method
listGrid.saveAllEdits();
In the EditCompletHandler :
I detect the creation with event.getOldRecord which in this case is null.
If not null I'm in the modify case.
To read the values, as the edited values are separated from the listgrid data, we need to use the event.getNewValues(). So after reading the new value and knowing if I need to create or modify I instanciate the right serializable object and I set its attribute with the new values
A problem arise to process the delete case, since the new created record can't be selected(even if the selected record is ok), so at the end as I don't know yet how to do it I added a context menu to avoid erasing the wrong record.
Note(31/10) : I was wrong to think it was ok, I had to use the Delete column with:
listGrid.setCanRemoveRecords(true);
listGrid.setRemoveIcon("16/supprimer.png");
It's the only way I found to delete a new fresh record.
Note(03/11/2011): The problem is: there is noway to be notified when the RemoveICon is clicked and one record deleted. So I think I will ask the user to either discard all the edits or save first and delete after... not really satisfying.... Widget working hand to hand with datasource everything is ok but without databinding there is a lot of work around to find.
listGrid.addEditCompleteHandler(new EditCompleteHandler() {
@Override
public void onEditComplete(EditCompleteEvent event) {
int rangee = event.getRowNum();
Record rec = event.getOldRecord();
if(rec == null){
SC.say("ADDING NEW RECORD");
}else{
SC.say("MODIFY THE SELECTED RECORD");
}
Map lesValeurs = event.getNewValues();
String newLibelle = (String) lesValeurs.get("libelle");
String newcode =(String) lesValeurs.get( "code");
Date newDebut =(Date) lesValeurs.get( "dateDeDebut");
Date newFin = (Date) lesValeurs.get( "dateDeFin");
MyObjectDTO myObject = new MyObjectDTO();
myObject.setLibelle(newLibelle);
............
ButtonItem btnAdd = new ButtonItem();
btnAdd.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
listGrid.setCanEdit(true);
listGrid.startEditingNew();
}
});
btnAdd.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
listGrid.setCanEdit(true);
listGrid.startEditingNew();
}
});
btnModify.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ListGridRecord currentRecord = listGrid.getSelectedRecord();
if(currentRecord != null){
listGrid.startEditing(listGrid.getRecordIndex (currentRecord),1,true);
}
}
});
Aucun commentaire:
Enregistrer un commentaire
It's your turn / Exprimez vous
What do you think, what would you like to be exposed, on which topic you don't agree....
Qu'en pensez vous, quels sujets aimeriez vous voir traités, sur quels point n'êtes vous pas d'accord....