ajax function while using the buble editor
ajax function while using the buble editor
I'm overriding the ajax function in my editor initialization and using bubble edit to allow single-cell edits of data in my table.
Upon submitting the edit, my ajax function is called with an action of "edit"
Sometimes the data object that is passed to the ajax function contains just the edited field (desired functionality).
Other times, several fields are returned in the data object. This seems to happen when some of the fields on the row being edited are empty.
Is there a way that I can ensure that only the edited field is returned?
obs_editor = new $.fn.dataTable.Editor( {
table: "#tblEditGoalObs", /* This table was built in the buildEditGoalObsTbl() function above */
fields: aoObsEditorFields, /* Built in buildEditGoalObsTbl() function */
ajax: function ( method, url, d, successCallback, errorCallback ) {
// This function replaces standard ajax functionaly because the data is based in a local object
// Create, edit and remove functionality is provided
var output = { data: [] };
if ( d.action === 'create' ) {
$.each( d.data, function (key, value) {
// Initialize all the elements of the new goal object
$.each(Object.keys(oObs2[0]),function() {
if (this != "GOALDESC") {
value[this] = "0";
}
});
var id = oObs2.length; // the length of the input array is the new keysince its simply an index into the array
value.DT_RowId = id; // Set up initial values for the new goal
value.DISPSEQ = id; // Set the display sequence so that the new goal appears after the existing ones
oObs2[ id ] = value; // append the new goal object to the array of existing goals
output.data.push( value ); // append the new goal object to the output object array
} );
}
else if ( d.action === 'edit' ) {
prompt('',JSON.stringify(d.data)); // sometimes contains only edited field, sometimes contains muliple fields
.
.
.
}
$('#tblEditGoalObs').on( 'click', 'tbody td:not(:first-child)', function (e) {
obs_editor.bubble( this, {
submit: 'changed',
buttons: { label: '<b>Save</b>', fn: function () {
this.submit();
}
}
} );
} );
Answers
That means that the value is changing, so we need to identify why that is happening when it is unexpected.
Can you give me a link to your page so I can see the full Editor configuration and the data being used with it please?
Thanks,
Allan
Unfortunately, I'm unable to give you a link. It is a fileserver-based application behind a firewall. But you have given me an idea.
Since the behavior is always associated with blank cells, I'm inclined to think that perhaps I'm loading them with a blank space and then somehow when I invoke the editor it converts them to a zero-length string. I'll investigate that.