Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82108

Accessing the JSON response within onSubmitComplete

$
0
0
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:

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

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

{
  "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"
    }
}

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

Thanks
- Tom



(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": "<i class='icon-pencil'></i> 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": "<i class='icon-trash'></i> Delete", "className": "btn btn-danger", "fn": function () { this.submit() } }
				]
		);
	});


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

		// Set to use server side processing
		"bServerSide": true,
		"sServerMethod": "POST",
		"sAjaxSource": "http://labour.revolutionaries.ie/data/db_admin_contacts/ctlr-datatables-get-data.tpl",

		// 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 '<p>€' + row.sPMTAMT + ' Membership ' + row.sPMTMEMCLASS + ' ' + data + '</p><span class="user-info"><em>On <strong>' + row.rCREATEDATEF +'</strong> at <strong>'+ row.rCREATETIME + '</strong></em></span> <span class="pull-right"><a class="btn btn-mini btn-primary editor_edit" href="#" title="Edit"><i class="icon-pencil"></i></a> <a class="btn btn-mini btn-danger editor_remove" href="#" title="Delete" role="button"><i class="icon-trash"></i></a></span>';
			 	}
			}
		],

		// Add table tools buttons
		"oTableTools": {
			"aButtons": [
				{
					"sExtends": "text", "sButtonText": "<i class='icon-plus'></i> 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": "<i class='icon-plus'></i> Add", "className": "btn btn-success", "fn": function () {editor.submit() } }
							]
						);
					}
				}
			]
		},

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

}(jQuery));

Viewing all articles
Browse latest Browse all 82108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>