Quantcast
Viewing all articles
Browse latest Browse all 82115

Ajax call inside mRender function

I am looking to call an ajax function inside the Datatables mRender function that will use an id from the present ajax source to get data from a different ajax source.

To put this into perspective, I have:

A listing of requisitions from different clients in one Datatable.

In this listing I have a client id. I want to get the client Name to be shown on the table instead of the client Id. However the Client Name and other client details are in the clients table hence these details are not in the requisitions json data. But I have the Client Id.

How do I use this to get client name inside the mrender function or Otherwise ? See what I have tried below:

{"sTitle":"Client", "sClass":"client",
	"mRender":function(data, type, row){


	 $.getJSON('<?php echo base_url().'requisitions/getClientInfo/'?>' + row.client_id, function(clientdata){
			var cdata = clientdata;
			
			for(var i =0; i < cdata.length; i++){
				var object = cdata[i];
				for(var key in object){
					var attrName = key;
					var attrValue = object[key];

					switch(attrName){
						case 'Name':
						
						var cname = attrValue;

						break;
					}
				}
			}
 			
		}) 

return cname;
		}

Thanks.

Viewing all articles
Browse latest Browse all 82115

Trending Articles



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