Accessing the JSON response within onSubmitComplete

Accessing the JSON response within onSubmitComplete

tomduketomduke Posts: 9Questions: 1Answers: 0
edited April 2013 in Editor
Hi,

I'm using server side processing and I'm trying to access a specific value from the JSON response after updating a record. In my initialisation I'm using the following:

[code]
editor.on('onSubmitComplete', function ( e, json, data ) {
alert('howdy');
});
[/code]

I know the event is being triggered as the alert is showing. My JSON is of the format:

[code]
{
"id": "id_value",
"row": {
"rCREATEDATE": "value_in_here",
"rCREATEDATEF": "value_in_here",
"rCREATETIME": "value_in_here",
"sPMTAMT": "value_in_here",
"sPMTTYPE": "value_in_here",
"sPMTMEMCLASS": "value_in_here",
"sPMTREF": "value_in_here"
}
}
[/code]

I have included the full initialisation code below. Any help greatly appreciated.

Thanks
- Tom



[code]
(function($){

$(document).ready(function() {
var editor = new $.fn.dataTable.Editor({
"ajaxUrl": "POST http://the_url",
"domTable": ".data-table-payments",
"fields": [
{
"type": "text",
"label": "Amount:",
"name": "sPMTAMT",
"attr": {
"type": "number"
}
},
{
"type": "select",
"label": "Payment Type:",
"name": "sPMTTYPE",
"ipOpts": [
{"label": "Membership", "value": "1" }
]
},
{
"type": "select",
"label": "Member Class:",
"name": "sPMTMEMCLASS",
"ipOpts": [
{"label": "Standard", "value": "STD" },
{"label": "Senior", "value": "SNR" },
{"label": "Youth", "value": "YTH" }
]
},
{
"label": "Ref:",
"name": "sPMTREF"
}
],
"events": {
"onPreSubmit": function ( o ) {
if ( o.data.sNOTETEXT === "" ) {
this.error('sPMTAMT', 'You must specify an amount');
return false;
}
}
}
});

editor.on('onPreSubmit', function ( e, data ) {
delete data.table;
data.sPMTLINKID = notelinkID;
});

editor.on('onSubmitComplete', function ( e, json, data ) {
alert(json.row.sPMTTYPE.value);
$("#nameWrapper small").html('howdy');
});


// Edit record
$('.data-table-payments').on('click', 'a.editor_edit', function (e) {
e.preventDefault();
editor.edit(
$(this).parents('tr')[0],
'Edit Payment', [
{"label": "Cancel", "className": "btn", "fn": function () { editor.close() } },
{"label": " Edit", "className": "btn btn-primary", "fn": function () { editor.submit() } }
]
);
});

// Delete a record - prompt for confirmation
$('.data-table-payments').on('click', 'a.editor_remove', function (e) {
e.preventDefault();

editor.message( "Are you sure you want to delete this payment?" );
editor.remove( $(this).parents('tr')[0],
'Delete Payment', [
{"label": "Cancel", "className": "btn", "fn": function () { editor.close() } },
{"label": " Delete", "className": "btn btn-danger", "fn": function () { this.submit() } }
]
);
});


$('.data-table-payments').dataTable({

// Set to use server side processing
"bServerSide": true,
"sServerMethod": "POST",
"sAjaxSource": "{url}",

// Additional params to be sent to the server
"fnServerParams": function ( aoData ) {
aoData.push(
{ "name": "dbToSearch", "value": "payments.db" },
{ "name": "defaultSearch", "value": "eqsPMTLINKIDdatarq=" + notelinkID + "&allreqd=T"},
{ "name": "defaultSort", "value": "derCREATEDATEsort=1&derCREATETIMEsort=2&rCREATETIMEtype=time"}
);
},

// Table structure and layout
"sDom": "fTrtp",
"iDisplayLength": 6,
"sPaginationType": "bootstrap-alternate",
"oLanguage": {
"sEmptyTable": "There are currently no notes.",
"sLengthMenu": "show _MENU_ records"
},

// Columns to be returned and their display format
"aoColumnDefs": [
{ "aTargets": [ 0 ], "mData": "rCREATEDATE", "sName": "rCREATEDATE", "bVisible": false },
{ "aTargets": [ 1 ], "mData": "rCREATEDATEF", "sName": "rCREATEDATEF", "bVisible": false },
{ "aTargets": [ 2 ], "mData": "rCREATETIME", "sName": "rCREATETIME", "bVisible": false },
{ "aTargets": [ 3 ], "mData": "sPMTTYPE", "sName": "sPMTTYPE", "bVisible": false },
{ "aTargets": [ 4 ], "mData": "sPMTAMT", "sName": "sPMTAMT", "bVisible": false },
{ "aTargets": [ 5 ], "mData": "sPMTMEMCLASS", "sName": "sPMTMEMCLASS", "bVisible": false },
{ "aTargets": [ 6 ], "mData": "sPMTREF", "sName": "sPMTREF", "sTitle": "Payments", "bSortable": false,
"mRender": function (data, type, row) {
return '€' + row.sPMTAMT + ' Membership ' + row.sPMTMEMCLASS + ' ' + data + 'On ' + row.rCREATEDATEF +' at '+ row.rCREATETIME + ' ';
}
}
],

// Add table tools buttons
"oTableTools": {
"aButtons": [
{
"sExtends": "text", "sButtonText": " New Payment", "sButtonClass": "btn-mini btn-success",
"fnClick": function ( button, config ) { editor.create(
'Add New Payment', [
{ "label": "Cancel", "className":"btn", "fn": function () {this.close() } },
{ "label": " Add", "className": "btn btn-success", "fn": function () {editor.submit() } }
]
);
}
}
]
},

// Set the initial table sort
"aaSorting": [[0,'desc']]
});
});

}(jQuery));
[/code]

Replies

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    I think you want just `json.row.sPMTTYPE` do you not? Your JSON structure shows that there is no `value` property for this parameter.

    Allan
  • tomduketomduke Posts: 9Questions: 1Answers: 0
    Allan,

    D'oh! Thanks for that - did the trick.

    - Tom
This discussion has been closed.