$.fn.dataTable.render.moment = function ( fmt ) {
	return function(d, type, row, meta) {
		if ( !d ) return '';
		return moment(d).format(fmt);
	}
};

$.fn.dataTable.render.comma = function ( val ) {
	return function(d, type, row, meta) {
		var str = '';
		if ( !d ) return 0;
		str += numberWithCommas(d);
		
		if ( val ) {
			str += val;
		}
		
		return str;
	}
};

$.fn.dataTable.render.numbering = function ( orderType, totalCount ) {
	return function(d, type, row, meta) {
		var num = 0;
		if ( !orderType ) orderType = 'asc';
		console.log('totalCount : ', totalCount);
		if ( orderType == 'asc' ) {
			num = meta.row + 1;
		} else if ( orderType == 'desc' ) {
			num = totalCount - meta.row;
		} else {
			num = meta.row + 1;
		}
		
		return num;
	}
};

var numbering = function(pagingInfo, meta) {
	var no = 0;
  	
	var currentPageNo = 0;
	var recordCountPerPage = 0;
	var totalRecordCount = 0;
	
	if ( pagingInfo ) {
		currentPageNo = nvl(pagingInfo.currentPageNo, 0);
		recordCountPerPage = nvl(pagingInfo.recordCountPerPage, 0);
		totalRecordCount = nvl(pagingInfo.totalRecordCount, 0);
	}
	
	no = totalRecordCount - (((currentPageNo - 1) * recordCountPerPage) + meta.row);
	
	var rtnHtml;
	rtnHtml = numberWithCommas(no);
	
	return rtnHtml;
}

var datatablesNumbering = function(meta, orderType, totalCount) {
	var num = 0;
	if ( !orderType ) orderType = 'asc';
	
	if ( orderType == 'asc' ) {
		num = meta.row + 1;
	} else if ( orderType == 'desc' ) {
		num = totalCount - meta.row;
	} else {
		num = meta.row + 1;
	}
	
	return numberWithCommas(num);
}

