Hi Valeriy
As you suggested here (April 30):
http://connect.remobjects.com/discussion/1356/odata-javascript
I tested a better integration between RODA/JS and Sencha Store (used in ExtJS and Sencha Touch), without grabbing data from datatable and feeds array store by loops …
Server side (Delphi):
function TNewService.MyGetData : Binary;
var
lDataSet: IDADataSet;
begin
result := Binary.Create;
try
JSONDataStreamer.Initialize(result, aiWrite);
lDataSet := Connection.NewDataset(‘SELECT …’,‘SQL’);
lDataSet.Open();
JSONDataStreamer.WriteDataset(lDataset, [woRows,woSchema], -1);
lDataSet := nil;
JSONDataStreamer.Finalize();
except
FreeAndNIL(result);
raise;
end;
end;
Client side (ExtJS) :
Ext.onReady(function() {
var channel = new RemObjects.SDK.HTTPClientChannel("http://localhost:8099/JSON");
var message = new RemObjects.SDK.JSONMessage();
var service = new NewService(channel, message);
service.MyGetData(function(result) {
// decode
var msg = base64.decode(result.replace(/(\n|\r)+/g, ""));
// data to array store
var data = JSON.parse(msg).datasets[0].data.rows;
// store
var store = new Ext.data.ArrayStore({
data : data,
fields : ['ID_FUNCIONARIO','LOGIN','DATA']
});
var grid = new Ext.grid.GridPanel({
title : 'Lista Usuários',
renderTo : Ext.getBody(),
autoHeight : true,
width : 400,
store : store,
columns: [ {
text : 'ID',
dataIndex: 'ID_FUNCIONARIO'
},{
text : 'LOGIN',
dataIndex: 'LOGIN'
},{
text : 'DATA',
dataIndex: 'DATA'
}],
viewConfig: {
stripeRows: true
}
});
}, showError);
});
Result:
On server side I used JSONStreamer returning Binary Data, and decoded it using:
base64.decode(result.replace(/(\n|\r)+/g, “”));
It is better to return a JSON string straight from server and no need to convert on client side? If yes, how to do it using JSONStreamer??
That’s it for now, when I have more time I will automate the process of configuring the fields of the grid, and other stuff …
Many thanks for your help.
Willian.