ID missing on second edit
ID missing on second edit
DataTables-1.10.5
Editor-1.4.0
I'm using inline editing features of DataTables Editor to queue changes that I want updated to the DB. On the first edit, the object being passed looks like this:
ON EDIT: {"action":"edit","data":{"spooler_group":"","ticker":"EWQ","low_bid_price":"0.05","high_bid_price":"32.724","low_ask_price":"21.816","high_ask_price":"272.7","max_order_size":"73340","5min_vwap":" ","disabled":"0"},"id":"4557516e"}
The second time around, the 'id' property is missing.
ON EDIT: {"action":"edit","data":{"spooler_group":"","ticker":"EWQ","low_bid_price":"0.06","high_bid_price":"32.724","low_ask_price":"21.816","high_ask_price":"272.7","max_order_size":"73340","5min_vwap":" ","disabled":"0"}}
here the relevant bits of code...
Can anyone explain what's going on?
var psc_editor = new $.fn.dataTable.Editor({
table: '#psc-t1',
idSrc: 'DT_RowId',
fields: [
{
label: 'spooler_group:',
name: 'spooler_group'
},
{
label: 'ticker:',
name: 'ticker'
},
{
label: 'low_bid_price:',
name: 'low_bid_price'
},
{
label: 'high_bid_price:',
name: 'high_bid_price'
},
{
label: 'low_ask_price:',
name: 'low_ask_price'
},
{
label: 'high_ask_price:',
name: 'high_ask_price'
},
{
label: 'max_order_size:',
name: 'max_order_size'
},
{
label: '5min_vwap:',
name: '5min_vwap'
},
{
label: 'disabled:',
name: 'disabled',
value: 0
}
],
ajax: function (method, url, data, successCallback, errorCallback) {
var _res = modifyQueuedStoreHandler(data);
successCallback(_res);
}
});
// submits changes when focus is changed from edited cell
psc_editor
.on('open', function (e, type) {
if (type === 'inline') {
// Listen for a tab key event when inline editing
$(document).on('keydown.editor', function ( e ) {
if ( e.keyCode === 9 ) {
e.preventDefault();
// Find the cell that is currently being edited
var cell = $('div.DTE').parent();
if ( e.shiftKey && cell.prev().length && cell.prev().index() !== 0 ) {
// One cell to the left (skipping the first column)
cell.prev().click();
}
else if ( e.shiftKey ) {
// Up to the previous row
cell.parent().prev().children().last(0).click();
}
else if ( cell.next().length ) {
// One cell to the right
cell.next().click();
}
else {
// Down to the next row
cell.parent().next().children().eq(1).click();
}
}
} );
}
})
.on( 'close', function () {
$(document).off('keydown.editor');
});
var psc_table = $('#psc-t1').DataTable({
dom: 'frtip',
idSrc: 'DT_RowId',
columns: [
{ data: 'spooler_group' },
{ data: 'ticker' },
{ data: 'low_bid_price' },
{ data: 'high_bid_price' },
{ data: 'low_ask_price' },
{ data: 'high_ask_price' },
{ data: 'max_order_size' },
{ data: '5min_vwap' },
{ data: 'disabled' }
],
order: [1, 'asc'],
pageLength: 75
});
psc_table
.on('click', 'tbody td:not(:nth-child(2))', function (e) {
psc_editor.inline(this, { submitOnBlur: true });
});
function modifyQueuedStoreHandler(data) {
console.log('ON EDIT: '+JSON.stringify(data));
if (isUpdated(data)) {
modifyQueuedStore(data, data.id);
}
return {'id': data.id}
}
Answers
Editor doesn't have a built in queuing mechanism as you have discovered, so it looks like your
modifyQueuedStoreHandler
function is effectively playing the part of the server-side process, however, it is not returning arow
parameter which it is best to do (documentation for client / server comms). Technically it isn't essential that it does (yet - it will be in 1.5 which will update the client / server protocol!), but it looks like it probably is required in this case.Allan