Fetch data with SmartClient LGPL version
-
22-04-2021 - |
Question
I want to use LGPL version of smart client to connect to my own server. I want the SmartClient to send a fetch request (with operation type, range etc) — I'll handle the rest. But I can't force SmartClient to do it. All I managed to do is force it to send a simple GET request. What should I add?
My code:
<HTML>
<HEAD>
<SCRIPT>var isomorphicDir="../isomorphic/";</SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Core.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Containers.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Grids.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Forms.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
<SCRIPT SRC=../isomorphic/skins/SmartClient/load_skin.js></SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
isc.DataSource.create({
ID:"countries",
dataURL:"countries_small.js",
fields:[
{name:"name", type:"text", primaryKey:true},
{name:"population"},
]
});
isc.ListGrid.create({
width: "100%",
height: 50,
dataSource: "countries",
drawAllMaxCells:0,
dataPageSize:1,
drawAheadRatio:1,
showAllRecords:false,
autoFetchData: true
});
</SCRIPT>
</BODY>
</HTML>
Solution
ok, i found a solution. the clue is to use RestDataSource.
isc.RestDataSource.create({
ID:"countriesDS",
dataFormat:"json",
dataURL: "partial.js",
operationBindings:[
{operationType:"fetch", dataProtocol:"postParams"}
],
fields:[
{title:"Name", name:"name", type:"text", primaryKey:true},
{title:"Population", name:"population", type:"text"}
]
});
isc.ListGrid.create({
width: "100%",
height: 60,
dataFetchMode:"paged",
dataSource: "countriesDS",
dataPageSize:2,
canEdit:true,
drawAheadRatio:1,
showAllRecords:false,
autoFetchData: true
});
and then, response may look like:
{ response:{
status:0,
startRow:0,
endRow:1,
totalRows:2,
data:[
{name:"Italy", population:"12"},
{name:"Germany", population:"121"}
]
}
}
OTHER TIPS
The thing you want to do is define your URLs for the other operations:
replace your dataURL in the dataSource object with individual bindings:
operationBindings:[
{operationType:"fetch", dataURL:"<fetch URL>"},
{operationType:"add",dataProtocol:"postParams", dataURL:"<insert URL>"},
{operationType:"update",dataProtocol:"postParams", dataURL:"<Update URL>"},
{operationType:"remove",dataProtocol:"postParams", dataURL:"<delete URL>"}]
Set an ID you grid and make it editable:
ID:"MyGrid"
canEdit: true,
editEvent: "click"
It should fire the update request when you move off the row.
Add buttons for new row and delete row with the following commands:
isc.IButton.create({title:"New",click:"MyGrid.startEditingNew()"});
isc.IButton.create({title:"Delete",click:"MyGrid.removeData()"});
Your Add URL should receive the request once you move off the row. The delete once you press the button.
I hope that's helpful.