Edit not happening after fnDraw

Edit not happening after fnDraw

GurubaranGurubaran Posts: 1Questions: 0Answers: 0
edited March 2013 in DataTables 1.8
I have inline editing enabled in my datatables. I update the data back to the server method. Everything works fine. When I try to edit a particular row and try to edit another row basically edit doesn't happen. meaning the already edited row has to become non-edited and the current row has to become edited.

I have a problem at this place.

if (nEditing !== null && nEditing != nRow) {
/*Currently editing - but not this row - restore the old before continuing to edit mode */
restoreRow(oTable, nEditing);
editRow(oTable, nRow);
nEditing = nRow;
}

Complete JS,

function editRow(oTable, nRow) {

var aData = oTable.fnGetData(nRow);
var acctualRowIndex = nRow.rowIndex - 1;
var jqTds = $('>td', nRow);
jqTds[4].innerHTML = '';
jqTds[5].innerHTML = ' ';
jqTds[6].innerHTML = '';
jqTds[7].innerHTML = '';
jqTds[8].innerHTML = 'Save' + '  ' + 'Cancel';

}

function saveRow ( oTable, nRow )
{
var jqInputs = $('input', nRow);

// server side update
$.ajax({
type: 'POST',
url: '/home/UpdateRowData/',
data:
{
"id": nRow.id,
"CRE_DT": jqInputs[3].value,
"CRE_USR": jqInputs[4].value,
"LAST_UPDT_DT": jqInputs[5].value,
"LAST_UPDT_USR": jqInputs[6].value
},
success: function(){
oTable.fnDraw();
}
});

}

function restoreRow ( oTable, nRow )
{
oTable.fnDraw();
}

var nEditing = null;
$('#example tbody td a').live('click', function(e) {
debugger;


e.preventDefault();
var nRow = $(this).parents('tr')[0];
if (nEditing !== null && nEditing != nRow) {
/*Currently editing - but not this row - restore the old before continuing to edit mode */
restoreRow(oTable, nEditing);
editRow(oTable, nRow);
nEditing = nRow;
} else if (nEditing == nRow && this.innerHTML == "Save") {
/* Editing this row and want to save it */
saveRow(oTable, nEditing);
nEditing = null;
} else if (nEditing == nRow && this.innerHTML == "Cancel") {
/* Editing this row and want to save it */
restoreRow(oTable, nEditing);
nEditing = null;
} else {
/* No edit in progress - let's start one */
editRow(oTable, nRow);
nEditing = nRow;
}


});

$(document).ready( function() {

var oTable = $('#example').dataTable({
"aoColumns": [
{ "mData": "MKTDEF_ID","bSearchable": true,"bSortable": true
// "mRender": function ( data, type, full ) {
// return fnCreateSelect([data]); }
},
{ "mData": "SRC_ID","bSearchable": true,"bSortable": true,"mRender": function ( data, type, full ) {
return fnCreateText([data]); }
},
{ "mData": "ONYX_CLIENT_ID","bSearchable": true,"bSortable": true,"mRender": function ( data, type, full ) {
return fnCreateCheckbox([data]); }
},
{ "mData": "MKTDEF_NM","bSearchable": true,"bSortable": true ,"mRender": function ( data, type, full ) {
return fnCreateButton([data]); }
},
{ "mData": "CRE_DT","bSearchable": true, "sType": "date","mRender": function ( data, type, full ) {
return $.datepicker.formatDate("mm/dd/yy",new Date(parseInt(data.substr(6)))); }
},
{ "mData": "CRE_USR","bSearchable": true,"bSortable": true},
{ "mData": "LAST_UPDT_DT","bSearchable": true, "sType": "date" ,"mRender": function ( data, type, full ) {
return $.datepicker.formatDate("mm/dd/yy",new Date(parseInt(data.substr(6)))); }
},
{ "mData": "LAST_UPDT_USR" },
{ "mData": null ,
"fnRender": function (oObj) {

return "Edit";
}},
// { "mData": null ,
// "fnRender": function (oObj) {
//
// return "Cancel";
// } }

],
"sAjaxSource": "@Url.Action("GetDataForServer", "Home")" ,
//"sUpdateURL": "@Url.Action("UpdateRecord", "Home")",


"fnServerData2": function (json)
{
if ( json.sEcho == 1 )
{

oTable.columnFilter({sPlaceHolder: "head:after",
aoColumns: json.aoColumnFilters.aoColumns

});
}
},

"oLanguage": { "sSearch": "Search all columns:"},
"aoColumnFilters":null,
"sScrollY": 200,
"bJQueryUI": true,
"sDom":'<"top"pfi><"clear">rt<"bottom"pl"<"clear">>',
"sPaginationType": "full_numbers",
"bServerSide": true,
"aaSorting": [[ 1, "desc" ]],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
//debugger;
$(nRow).attr('id', aData.MKTDEF_ID );
return nRow;

} });

Thanks for taking a look and you helps :-)

Guru
This discussion has been closed.