I managed to create a working ListGrid in the following manner :
and then filling the grid like this using a RecordList
This is all working fine but now I want to use a filter on the ListGrid (using listGrid.setShowFilterEditor(true); and listGrid.setFilterOnKeyPress(true);
This however does not seem to work when using a RecordList as data for the ListGrid.
It seems that a DataSource must be used for this.
I tried creating a DataSource but the problem is that my table is always empty.
The things I did.
Create a DataSource class :
Then I created a ListGrid.
And finally
The result of all this is that I get an empty ListGrid.
The headers are shown correctly however. Since I removed listGrid.setFields() when swithing to a DataSource this means that the column headers really are coming from the DataSource correctly. But I am unable to fetch the data itself.
Anyone has a quick overview of how to create and use a clientOnly dataSource. And not using a setDataUrl() like all examples I find in the showcase do, but really filling up the datasource with data from an array or a list in the code.
Thanks
Code:
private ListGrid listGrid = new ListGrid(); listGrid.setShowAllRecords(true); ListGridField employeeNameField = new ListGridField("employeeName","EmployeeName"); ListGridField emailField = new ListGridField("email", "Email"); ListGridField phoneWorkField = new ListGridField("phonework", "Phone work"); ListGridField phoneMobileField = new ListGridField("phonemobile", "Phone mobile); listGrid.setFields(employeeNameField, emailField, phoneWorkField, phoneMobileField); listGrid.setAutoFetchData(true);
Code:
RecordList data = new RecordList(); for (EmployeeResponse employee:response) { ListGridRecord record = new ListGridRecord(); record.setAttribute("employeeName", employee.getEmployeeName()); record.setAttribute("email", employee.getEmail1()); record.setAttribute("phonework", employee.getPhoneWork()); record.setAttribute("phonemobile", employee.getPhoneMobile()); data.add(record); } listGrid.setData(data);
This is all working fine but now I want to use a filter on the ListGrid (using listGrid.setShowFilterEditor(true); and listGrid.setFilterOnKeyPress(true);
This however does not seem to work when using a RecordList as data for the ListGrid.
It seems that a DataSource must be used for this.
I tried creating a DataSource but the problem is that my table is always empty.
The things I did.
Create a DataSource class :
Code:
public class EmployeeDataSource extends DataSource { public EmployeeDataSource() { setID("abc"); DataSourceTextField employeeNameField = new DataSourceTextField("employeeName", I18NMessages.getMessage(4182)); DataSourceTextField emailField = new DataSourceTextField("email", I18NMessages.getMessage(4377)); DataSourceTextField phoneWorkField = new DataSourceTextField("phonework", I18NMessages.getMessage(2338)); DataSourceTextField phoneMobileField = new DataSourceTextField("phonemobile", I18NMessages.getMessage(2196)); this.setFields(employeeNameField, emailField, phoneWorkField, phoneMobileField); this.setClientOnly(true); } }
Code:
private ListGrid listGrid = new ListGrid(); listGrid.setShowAllRecords(true); listGrid.setShowFilterEditor(true); listGrid.setFilterOnKeypress(true); listGrid.setAutoFetchData(true);
Code:
ListGridRecord[] records = new ListGridRecord[response.size()]; for (int i = 0; i < records.length; i++) { records[i] = new ListGridRecord(); records[i].setAttribute("employeeName", response.get(i).getEmployeeName()); records[i].setAttribute("email", response.get(i).getEmail1()); records[i].setAttribute("phonework", response.get(i).getPhoneWork()); records[i].setAttribute("phonemobile", response.get(i).getPhoneMobile()); } dataSource.setCacheData(records); dataSource.invalidateCache();
The result of all this is that I get an empty ListGrid.
The headers are shown correctly however. Since I removed listGrid.setFields() when swithing to a DataSource this means that the column headers really are coming from the DataSource correctly. But I am unable to fetch the data itself.
Anyone has a quick overview of how to create and use a clientOnly dataSource. And not using a setDataUrl() like all examples I find in the showcase do, but really filling up the datasource with data from an array or a list in the code.
Thanks
Comment