Hello
Recently I started to try ListGrid in our application. It's too much to rework to use it's standard way of fetching the data, so I decided to populate records manually. The obvious way of doing this is to use ListGrid.setData().
I use GWT 2.0.3, SmartGWT 2.1, Firefox 3.0.19 in OS Kubuntu 9.10.
Here is my code (after instantiation of this view the create() method is invoked to get the grid and place it to the page):
The problem is that in the Web mode it works OK but in the development mode the table is not populated with the data.
Recently I started to try ListGrid in our application. It's too much to rework to use it's standard way of fetching the data, so I decided to populate records manually. The obvious way of doing this is to use ListGrid.setData().
I use GWT 2.0.3, SmartGWT 2.1, Firefox 3.0.19 in OS Kubuntu 9.10.
Here is my code (after instantiation of this view the create() method is invoked to get the grid and place it to the page):
Code:
public class IncidentsTableView { protected ListGrid incidentGrid; protected List<Incident> incidentsList; public IncidentsTableView() { incidentGrid = new ListGrid() { public DataSource getRelatedDataSource(ListGridRecord record) { return IncidentDs.getInstance(); } protected Canvas getExpansionComponent(ListGridRecord record) { final ListGrid workorderGrid = new ListGrid(); workorderGrid.setWidth(500); workorderGrid.setHeight(224); workorderGrid.setCanEdit(false); return workorderGrid; } }; initTable(); incidentGrid.draw(); } protected void initTable() { incidentGrid.setStyleName(MainStyles.CONST_WIDTH_CLASS); incidentGrid.setWidth(600); incidentGrid.setHeight(500); incidentGrid.setDrawAheadRatio(4); incidentGrid.setCanExpandRecords(true); incidentGrid.setAutoFetchData(false); incidentGrid.setDataSource(IncidentDs.getInstance()); incidentGrid.setDataFetchMode(FetchMode.LOCAL); incidentGrid.setShowAllRecords(true); } public Widget create() throws IllegalStateException { return incidentGrid; } public void setTableData(List<Incident> incidentsList) { this.incidentsList = incidentsList; ListGridRecord[] gridRecords = IncidentDs.convertIncidentsListToRecords(incidentsList); RecordList recordList = new RecordList(gridRecords); incidentGrid.setData(recordList); } private static class IncidentDs extends DataSource implements ClientOnlyDataSources { private static final String NUMBER_PROPERTY = "number"; private static final String DATE_PROPERTY = "date"; private static final String SUBJECT_PROPERTY = "subject"; private static final String STATUS_PROPERTY = "status"; private static final String REQUESTER_PROPERTY = "requester"; private static final String CONTACT_PERSON_PROPERTY = "contactPerson"; private static final String DEPARTMENT_PROPERTY = "department.our"; private static final String ACTIONS_PROPERTY = "actions"; private static IncidentDs instance = null; public IncidentDs() { setClientOnly(true); DataSourceTextField idField = new DataSourceTextField(NUMBER_PROPERTY, L10n.getMessages().number(), 100); DataSourceDateField dateField = new DataSourceDateField(DATE_PROPERTY, L10n.getMessages().date(), 100); DataSourceTextField subjectField = new DataSourceTextField(SUBJECT_PROPERTY, L10n.getMessages().subject(), 100); DataSourceEnumField statusField = new DataSourceEnumField(STATUS_PROPERTY, L10n.getMessages().status()); int valuesCount = Status.values().length; Map<String, String> values = new HashMap<String, String>(); for (int i = 0; i < valuesCount; i++) { values.put(Status.values()[i].getIncidentsId(), Status.values()[i].toString()); } statusField.setValueMap(values); DataSourceTextField requesterField = new DataSourceTextField(REQUESTER_PROPERTY, L10n.getMessages().requester(), 100); DataSourceTextField contactPersonField = new DataSourceTextField(CONTACT_PERSON_PROPERTY, L10n.getMessages().contactPerson(), 100); DataSourceTextField departmentField = new DataSourceTextField(DEPARTMENT_PROPERTY, L10n.getMessages().department(), 100); DataSourceTextField actionsField = new DataSourceTextField(ACTIONS_PROPERTY, L10n.getMessages().actions(), 100); setFields(idField, dateField, subjectField, statusField, requesterField, contactPersonField, departmentField, actionsField); } public static IncidentDs getInstance() { if (instance == null) { instance = new IncidentDs(); } return instance; } public static ListGridRecord[] convertIncidentsListToRecords(List<Incident> incidentsList) { ListGridRecord[] listGridRecords = new ListGridRecord[incidentsList.size()]; int i = 0; for (Incident incident : incidentsList) { ListGridRecord listGridRecord = new ListGridRecord(); listGridRecord.setAttribute(NUMBER_PROPERTY, incident.getIncidentId()); listGridRecord.setAttribute(DATE_PROPERTY, incident.getFromDate()); listGridRecord.setAttribute(SUBJECT_PROPERTY, incident.getSubjectId()); listGridRecord.setAttribute(STATUS_PROPERTY, incident.getStatusDesc()); listGridRecord.setAttribute(REQUESTER_PROPERTY, incident.getRequester()); listGridRecord.setAttribute(CONTACT_PERSON_PROPERTY, incident.getContactPerson()); listGridRecord.setAttribute(DEPARTMENT_PROPERTY, incident.getDepartment()); listGridRecord.setAttribute(ACTIONS_PROPERTY, incident); listGridRecords[i++] = listGridRecord; } return listGridRecords; } } }
Comment