Originally posted by mnenchev
I don;t have access to download it now, will try this at home.
Thanks a lot.
final SmartGWTDataSource<TestDTO, SmartGWTDataConverter<TestDTO>, DataServiceAsync<TestDTO>> ds = new SmartGWTDataSource<TestDTO, SmartGWTDataConverter<TestDTO>, DataServiceAsync<TestDTO>>(new TestDataConverter(), ServiceUtils.getTestServiceAsync(), RecordType.GRID);
public void executeFetch(final String requestId, final DSRequest request, final DSResponse response) { Object critObject = request.getCriteria().getAttributeAsObject(PilotCriteria.SEARCH_CRITERIA); if (critObject != null) { getService().getAll(critObject, new AsyncCallback<List<IDTO>>() { public void onFailure(Throwable throwable) { response.setStatus(RPCResponse.STATUS_FAILURE); processResponse(requestId, response); } public void onSuccess(List<IDTO> contractDTOs) { SC.say(contractDTOs.size() + " документ(-ов) найдено."); List<AbstractRecord> records = new ArrayList<AbstractRecord>(); if (contractDTOs != null && contractDTOs.size() > 0) { for (IDTO document : contractDTOs) { records.add(createRecord(document)); } } response.setData(records.toArray(new AbstractRecord[]{})); response.setTotalRows(records.size()); processResponse(requestId, response); } }); } else { getService().getAll(new AsyncCallback<List<IDTO>>() { public void onFailure(Throwable throwable) { response.setStatus(RPCResponse.STATUS_FAILURE); processResponse(requestId, response); } public void onSuccess(List<IDTO> dataList) { List<AbstractRecord> records = new ArrayList<AbstractRecord>(); if (dataList != null && dataList.size() > 0) { for (IDTO document : dataList) { records.add(createRecord(document)); } } response.setData(records.toArray(new AbstractRecord[]{})); response.setTotalRows(records.size()); processResponse(requestId, response); } }); } }
public class TestEntry implements EntryPoint { @Override public void onModuleLoad() { final ListGrid grid = new ListGrid(); ListGridField lgf = new ListGridField("firstname", "First Name"); ListGridField lgf2 = new ListGridField("lastname", "Last Name"); grid.setShowFilterEditor(true); grid.setAutoFetchAsFilter(true); grid.setAutoFetchData(true); grid.setShowAllRecords(false); grid.setFields(lgf, lgf2); DataSource ds = new MyDS(); grid.setDataSource(ds); RootPanel.get().add(grid); } public static class MyDS extends GwtRpcDataSource { @Override protected void executeAdd(String requestId, DSRequest request, DSResponse response) { } @Override protected void executeRemove(String requestId, DSRequest request, DSResponse response) { } @Override protected void executeUpdate(String requestId, DSRequest request, DSResponse response) { } @Override protected void executeFetch(String requestId, DSRequest request, DSResponse response) { GWT.log("Fetch", null); ListGridRecord[] records = new ListGridRecord[3]; ListGridRecord lgr = new ListGridRecord(); lgr.setAttribute("firstname", "John"); lgr.setAttribute("lastname", "Smith"); records[0] = lgr; lgr = new ListGridRecord(); lgr.setAttribute("firstname", "Mike"); lgr.setAttribute("lastname", "Smith"); records[1] = lgr; lgr = new ListGridRecord(); lgr.setAttribute("firstname", "Bill"); lgr.setAttribute("lastname", "Roberts"); records[2] = lgr; response.setData(records); response.setTotalRows(records.length); processResponse(requestId, response); } } }
Comment