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

How do I add and extra parameter to mRender in jquery.dataTables.js (version 1.9)

$
0
0
Greetings,
I am working on adding an extra parameter to mRender in the datatables plugin called sFormat which should be passed to oCol in order to format data dynamically coming from JSON. Right now I have the datatable populating with raw unformatted data. These are the functions that I have in my HTML page:
----------------DATATABLES INIT FUNCTIONS--------------------------------
 function fnBuildTable(metadata, data){
    	
		var aoColumns = [];
		
		for(var i=0;i< metadata.length; i++) {
			var coldef = metadata[i];

		    var column = {
			   	"mData": coldef.fieldName, 
			   	"sTitle": coldef.headerName,
			   	"sClass": "right",
			   	"sWidth": "8%",
			   	"mRender": fnRender,
			   	"sFormat": coldef.format
		    };
		    aoColumns.push(column);
		 }

function fnRender(data, type, full, sFormat){
		function fnRender(data, type, full){
		var oTable = $("#tableChain").dataTable();
		var oSettings = oTable.fnSettings();
	        var sFormat = $.format.number(data, "#,##0.00");		
		return data;
	};
------------------------------------------------------------------------
Some columns will be cities and countries with hyperlinks so I formatted that in aoColumnDefs like this:
-----------------------DATATABLES INIT----------------------------------
				"aoColumns": aoColumns,//CALLS ARRAY FROM ABOVE
				"aoColumnDefs": [{ 
				"bVisible": true, "aTargets": [1],				
				"fnRender":
					function (o) {					
					var	num = "<a href=forecast.html?fips=";
					num += o.aData.FIPS;
					num += "&t90=3&lookback=12&dtS=1983-01-31&dtE=2017-01-31&geoname=";
					num += o.aData.Geography.replace(/ /g, "+");
					num += " target=new>";
					num += o.aData.Geography;
					num += " </a>";
					return num;
				},
				}]
-------------------------------------------------------------------------------------------------
AND this is the part in jquery.dataTables.js 1.9 that I am trying to add the parameter sFormat so that specific numeral values will get formatted accordingly.
----------------------DATATABLES 1.9 PLUGIN------------------------------------------------------
		/* Cache the data get and set functions for speed */
			var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
			var mData = _fnGetObjectDataFn( oCol.mData ); 		
			oCol.fnGetData = function (oData, sSpecific) {
				var innerData = mData( oData, sSpecific );	
				var sFormat = $.format.number(innerData, "#,##0.00");//NEED TO PUT sFormat somewhere to format number data coming in from JSON
                                
				if ( oCol.mRender && (sSpecific && sSpecific !== '') )
				{
					return mRender( innerData, sSpecific, oData );		
				}
				return innerData;
};

Viewing all articles
Browse latest Browse all 82121

Trending Articles



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