select the created record onSubmitSuccess
select the created record onSubmitSuccess
Hi folks,
I'm using the dataTable Editor recently and i want to achieve the following :
I want to select automatically the new record added to the dataTable in OnSubmitSuccess, to be able to update its data from the data sent from server.
I use the code bellow for edit, and i want to use the same logic for create, but i don't know how to select the created record:
[code]
editor.on( 'onSubmitSuccess', function (e, json, data)
{
// Get associated domTable
var domTable = e.currentTarget.s.domTable.replace("#","")
var fieldId;
// Get the tableTools
var oTT = TableTools.fnGetInstance(domTable);
var aSelectedTrs;
var sSelectedData;
var realValue;
var nameSplited;
var fieldName;
if(oTT)
{
// Get the selected record
aSelectedTrs = oTT.fnGetSelected();
sSelectedData = oTT.fnGetSelectedData();
if( aSelectedTrs.length > 0)
{
// Get all fields autoComplete
for (var i = 0 ; i < e.currentTarget.s.fields.length; i++)
{
if(e.currentTarget.s.fields[i].type == "autoComplete")
{
fieldId = "#"+e.currentTarget.s.fields[i].id;
// Update the td value and realValue attribute associated
$($(aSelectedTrs[0]).children()[i]).attr("realValue",$(fieldId).attr("realValue"));
$($(aSelectedTrs[0]).children()[i]).html($(fieldId).val());
/* Update the associated data with the display value
because the data was updated using the realValue
*/
sSelectedData[0][e.currentTarget.s.fields[i].name] = $(fieldId).val();
}
else
{
// update data
$($(aSelectedTrs[0]).children()[i]).html(json.data[e.currentTarget.s.fields[i].name]);
sSelectedData[0][e.currentTarget.s.fields[i].name] = json.data[e.currentTarget.s.fields[i].name];
}
}
}
}
[/code]
Thank you in advance for your help
I'm using the dataTable Editor recently and i want to achieve the following :
I want to select automatically the new record added to the dataTable in OnSubmitSuccess, to be able to update its data from the data sent from server.
I use the code bellow for edit, and i want to use the same logic for create, but i don't know how to select the created record:
[code]
editor.on( 'onSubmitSuccess', function (e, json, data)
{
// Get associated domTable
var domTable = e.currentTarget.s.domTable.replace("#","")
var fieldId;
// Get the tableTools
var oTT = TableTools.fnGetInstance(domTable);
var aSelectedTrs;
var sSelectedData;
var realValue;
var nameSplited;
var fieldName;
if(oTT)
{
// Get the selected record
aSelectedTrs = oTT.fnGetSelected();
sSelectedData = oTT.fnGetSelectedData();
if( aSelectedTrs.length > 0)
{
// Get all fields autoComplete
for (var i = 0 ; i < e.currentTarget.s.fields.length; i++)
{
if(e.currentTarget.s.fields[i].type == "autoComplete")
{
fieldId = "#"+e.currentTarget.s.fields[i].id;
// Update the td value and realValue attribute associated
$($(aSelectedTrs[0]).children()[i]).attr("realValue",$(fieldId).attr("realValue"));
$($(aSelectedTrs[0]).children()[i]).html($(fieldId).val());
/* Update the associated data with the display value
because the data was updated using the realValue
*/
sSelectedData[0][e.currentTarget.s.fields[i].name] = $(fieldId).val();
}
else
{
// update data
$($(aSelectedTrs[0]).children()[i]).html(json.data[e.currentTarget.s.fields[i].name]);
sSelectedData[0][e.currentTarget.s.fields[i].name] = json.data[e.currentTarget.s.fields[i].name];
}
}
}
}
[/code]
Thank you in advance for your help
This discussion has been closed.
Replies
I resolved my problem by doing the following code.
[code]
editor.on( 'onSubmitSuccess', function (e, json, data)
{
if(oTable){
var oTableNodes = oTable.fnGetNodes();
var oTableData = oTable.fnGetData();
if((oTableNodes && oTableNodes.length > 0) && (oTableData && oTableData.length > 0) ){
var oTNewNode = oTableNodes[oTableNodes.length - 1]
var oTNewData = oTableData[oTableData.length - 1]
// Get all fields
for (var i = 0 ; i < e.currentTarget.s.fields.length; i++)
{
$($(oTNewNode).children()[i]).html(json.data[e.currentTarget.s.fields[i].name]);
oTNewData[e.currentTarget.s.fields[i].name] = json.data[e.currentTarget.s.fields[i].name];
}
}
}
}
[/code]
Any suggestion to do it better is more than welcome.