我尝试在DataGrid
中显示数据,但它不起作用。
以下是我的代码片段:
public DataGridAffiche2() {
super(true);
AbsolutePanel absolutePanel = new AbsolutePanel();
setWidget(absolutePanel);
absolutePanel.setSize("1002px", "404px");
Label lblJaiAjoutAu = new Label("j'ai ajouté au dessous de cette ligne");
absolutePanel.add(lblJaiAjoutAu, 10, 20);
System.out.println("ttt");
final DataGrid<Employe> grid=new DataGrid<Employe>();
System.out.println("ttt1");
final List<Employe> values=new ArrayList<Employe>();
System.out.println("ttt2");
Employe p=new Employe();
System.out.println("ttt3");
rpc.afficheEmploye(new AsyncCallback<List<Employe>>() {
@Override
public void onSuccess(List<Employe> result) {
System.out.println("ttt4");
List<Employe> values=new ArrayList<Employe>();
System.out.println("ttt5");
System.out.println("datagridaffich2 avant values");
System.out.print(values);
System.out.println("ttt6");
for(Employe p:result ){
System.out.println("ttt7");
values.add(p);
System.out.println("values hadek est "+p);
System.out.println("firstName du client est ");
System.out.println("firstName du client est "+values);
System.out.println("hada howa p "+result);
}
}
@Override
public void onFailure(Throwable caught) {
System.out.println("ttt8");
}
});
System.out.println("ttt9");
grid.setAutoHeaderRefreshDisabled(true);
grid.setAutoFooterRefreshDisabled(true);
ListHandler<Employe> sortHandler = new ListHandler<Employe>(values);
grid.addColumnSortHandler(sortHandler);
grid.setRowData(values);
grid.setVisible(true);
grid.setSize("839px", "323px");
grid.setEmptyTableWidget(new Label("Message afficher test"));
System.out.println("ttt10");
Column<Employe, String> nameColumn = new Column<Employe, String>(new EditTextCell()) {
@Override
public String getValue(Employe object) {
return object.getFirstname();
}
};
abstract class PendingChange<T> {
private final Employe Employe;
private final T value;
public PendingChange(Employe Employe, T value) {
this.Employe = Employe;
this.value = value;
}
public void commit() {
doCommit(Employe, value);
}
protected abstract void doCommit(Employe Employe, T value);
}
final String[] FirstNameData = new String[] {
"Hollie", "Emerson", "Healy", "Brigitte", "Elba", "Claudio",
"Dena", "Christina", "Gail", "Orville", "Rae", "Mildred",
"Candice", "Louise", "Emilio", "Geneva", "Heriberto", "Bulrush",
"Abigail", "Chad", "Terry", "Bell"
};
class BirthdayChange extends PendingChange<Date> {
public BirthdayChange(Employe Employe, Date value) {
super(Employe, value);
}
protected void doCommit(Employe Employe, Date value) {
Employe e=new Employe();
e.setDate_nais(value);
}
}
Column<Employe, Date> datepeckercolumn1 = new Column<Employe, Date>(new DatePickerCell()) {
@Override
public Date getValue(Employe object) {
return object.getDate_nais();
}
};
datepeckercolumn1.setSortable(true);
grid.addColumn(datepeckercolumn1, "datepeckerDJ");
List<Employe> items = grid.getVisibleItems();
if (items.size() != 0) {
int totalAge = 0;
for (Employe item : items) {
totalAge ++;
}
countnom="nombre d'Employe : " + totalAge;
}
grid.addColumn(nameColumn,"Nom",countnom);
Column<Employe, String> prenomColumn = new Column<Employe, String>(new EditTextCell()) {
@Override
public String getValue(Employe object) {
return object.getLastname();
}
};
prenomColumn.setSortable(true);
sortHandler.setComparator(prenomColumn, new Comparator<Employe>() {
@Override
public int compare(Employe o1, Employe o2) {
return o1.getLastname().compareTo(o2.getLastname());
}
});
grid.addColumn(prenomColumn,"Prenom");
Column<Employe, String> adresseColumn = new Column<Employe, String>(new EditTextCell()) {
@Override
public String getValue(Employe object) {
return object.getEmailaddress();
}
};
grid.addColumn(adresseColumn,"Adresse");
absolutePanel.add(grid, 10, 50);
Column<Employe, Date> datepeckercolumn = new Column<Employe, Date>(new DatePickerCell()) {
@Override
public Date getValue(Employe object) {
return (Date) null;
}
};
datepeckercolumn.setSortable(true);
grid.addColumn(datepeckercolumn, "datepeckerDJ");
Column<Employe, String> btn = new Column<Employe, String>(new ButtonCell()) {
@Override
public String getValue(Employe object) {
return (String) null;
}
};
grid.addColumn(btn, "Buttun");
ListBox lb = new ListBox();
lb.addItem("foo");
lb.addItem("bar");
lb.addItem("baz");
lb.addItem("toto");
lb.addItem("tintin");
lb.setVisibleItemCount(5);
Column<Employe, String> Combobox = new Column<Employe, String >(new SelectionCell(new ArrayList<String>())) {
@Override
public String getValue(Employe object) {
return (String) null;
}
};
grid.addColumn(Combobox, "ComboBox");
Button btnQuiter = new Button("Quiter");
btnQuiter.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
DataGridAffiche2.this.hide();
}
});
CellBrowser cellBrowser = new CellBrowser(
new TreeViewModel() {
final AbstractDataProvider<String> dataProvider = new ListDataProvider<String>();
final AbstractSelectionModel<String> selectionModel = new NoSelectionModel<String>();
@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
return new DefaultNodeInfo<String>(dataProvider, new TextCell(), selectionModel, null);
}
@Override
public boolean isLeaf(Object value) {
return true;
}
}, null);
absolutePanel.add(cellBrowser);
absolutePanel.add(btnQuiter, 919, 316);
Button btnAfficheDatagrid = new Button("Affiche datagrid");
btnAfficheDatagrid.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
absolutePanel.add(btnAfficheDatagrid, 863, 267);
}
public List<Employe> afficheEmploye() {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
List<Employe> lp = new ArrayList<Employe>();
Query q = new Query("Employe");
List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
for(Entity employe :results ){
Employe p = new Employe();
datastore.put(employe);
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asIterable()) {
String firstName = (String) result.getProperty("firstName");
String lastName = (String) result.getProperty("lastName");
System.out.println(firstName + " " + lastName + ", inches tall jdid");
}
lp.add(p);
}
return lp;
}
答案 0 :(得分:0)
在您的rpc调用的成功方法中,您正在创建新的本地列表并将数据添加到名为值的本地列表中,该列表永远不会传递到您的数据网格。
这有两个解决方案
1)使用
dataGrid.setRowData(values);
dataGrid.redraw();
成功方法。
2)或使用ListDataProvider。