Hi, i have a problem with updateData:
in the code (listed below) there are an 'update' button, which makes an updateData operation on the dataSource 'contacts', the problem occurs when i add various records with the button 'add', and then i press the button 'update' (which detect all the modified records), producing incorrect display of the updated values in the listgrid. ¿ is there a problem in the code or i am missing something ?
note: i most to use discardAllEdits() in the update button, because getAllEditRows.
the code:
isc.DataSource.create({
ID:"contacts",
dataFormat:"xml",
recordXPath:"//Table",
//dataURL:'http://192.168.1.9/Webservice2/service2.asmx/executeQuery?sSql=%20',
fields:{
au_id:{name:"au_id", primaryKey:true}, // primary key is necessary for removeData
au_lname:{name:"au_lname"},
au_fname:{name:"au_fname"},
address:{name:"address"}
},
operationBindings:
[
{
operationType:"fetch",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/executeQuery"
},
{
operationType:"add",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/insert"
},
{
operationType:"remove",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/remove"
},
{
operationType:"update",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/update"
}
]
});
isc.ListGrid.create({
ID: "boundGrid",
dataSource: "contacts",
width: "100%",
height:"80%",
//autoFetchData: true
canEdit:true,
editByCell:true,
headerHeight:15});
isc.IButton.create({
title: "fetch",
width: 120,
left: 100,
top: 350,
click: function()
{
boundGrid.data.invalidateCache();
boundGrid.fetchData({sSql:'X'},null,{useHttpProxy:true}); //boundGrid.canEdit=false;
//boundGrid.fetchData({sSql:' '},'boundGrid.canEdit=true');
}
});
isc.IButton.create({
title: "Add",
width: 120,
left: 250,
top: 350,
click: function ()
{
//boundGrid.data.invalidateCache();
boundGrid.addData({au_id:'a',au_lname:'b',au_fname:'c',address:'d'},null,{useHttpProxy:true});
}
});
isc.IButton.create({
title: "remove selected",
width: 120,
left: 400,
top: 350,
click: function ()
{
if (boundGrid.getSelectedRecord())
{
//boundGrid.data.invalidateCache();
boundGrid.removeData(boundGrid.getSelectedRecord(),null,{useHttpProxy:true});
}
}
});
isc.IButton.create({
title: "update",
width: 120,
left: 550,
top: 350,
click: function ()
{
numrec=boundGrid.getAllEditRows();
var rec;
if (numrec.getLength()>0)
{
for (var i=0;i<numrec.getLength();i++)
{
rec=boundGrid.data.get(numrec[i]);
boundGrid.updateData(rec,function(dsResponse,data, dsRequest)
{
var rowNum = boundGrid.data.indexOf(data[0]);
if(rowNum >= 0) boundGrid.selectRecord(rowNum);
},{useHttpProxy:true});
}
boundGrid.discardAllEdits();
}
}
});
boundGrid.fetchData({sSql:'%'},null,{useHttpProxy:true}); // only returns a blank record
Thanks
in the code (listed below) there are an 'update' button, which makes an updateData operation on the dataSource 'contacts', the problem occurs when i add various records with the button 'add', and then i press the button 'update' (which detect all the modified records), producing incorrect display of the updated values in the listgrid. ¿ is there a problem in the code or i am missing something ?
note: i most to use discardAllEdits() in the update button, because getAllEditRows.
the code:
isc.DataSource.create({
ID:"contacts",
dataFormat:"xml",
recordXPath:"//Table",
//dataURL:'http://192.168.1.9/Webservice2/service2.asmx/executeQuery?sSql=%20',
fields:{
au_id:{name:"au_id", primaryKey:true}, // primary key is necessary for removeData
au_lname:{name:"au_lname"},
au_fname:{name:"au_fname"},
address:{name:"address"}
},
operationBindings:
[
{
operationType:"fetch",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/executeQuery"
},
{
operationType:"add",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/insert"
},
{
operationType:"remove",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/remove"
},
{
operationType:"update",
dataFormat:"xml",
recordXPath:"//Table",
dataURL:"http://192.168.1.9/Webservice2/service2.asmx/update"
}
]
});
isc.ListGrid.create({
ID: "boundGrid",
dataSource: "contacts",
width: "100%",
height:"80%",
//autoFetchData: true
canEdit:true,
editByCell:true,
headerHeight:15});
isc.IButton.create({
title: "fetch",
width: 120,
left: 100,
top: 350,
click: function()
{
boundGrid.data.invalidateCache();
boundGrid.fetchData({sSql:'X'},null,{useHttpProxy:true}); //boundGrid.canEdit=false;
//boundGrid.fetchData({sSql:' '},'boundGrid.canEdit=true');
}
});
isc.IButton.create({
title: "Add",
width: 120,
left: 250,
top: 350,
click: function ()
{
//boundGrid.data.invalidateCache();
boundGrid.addData({au_id:'a',au_lname:'b',au_fname:'c',address:'d'},null,{useHttpProxy:true});
}
});
isc.IButton.create({
title: "remove selected",
width: 120,
left: 400,
top: 350,
click: function ()
{
if (boundGrid.getSelectedRecord())
{
//boundGrid.data.invalidateCache();
boundGrid.removeData(boundGrid.getSelectedRecord(),null,{useHttpProxy:true});
}
}
});
isc.IButton.create({
title: "update",
width: 120,
left: 550,
top: 350,
click: function ()
{
numrec=boundGrid.getAllEditRows();
var rec;
if (numrec.getLength()>0)
{
for (var i=0;i<numrec.getLength();i++)
{
rec=boundGrid.data.get(numrec[i]);
boundGrid.updateData(rec,function(dsResponse,data, dsRequest)
{
var rowNum = boundGrid.data.indexOf(data[0]);
if(rowNum >= 0) boundGrid.selectRecord(rowNum);
},{useHttpProxy:true});
}
boundGrid.discardAllEdits();
}
}
});
boundGrid.fetchData({sSql:'%'},null,{useHttpProxy:true}); // only returns a blank record
Thanks
Comment