Using column.render and getting column properties
Using column.render and getting column properties
Hi,
this is my very first post in this forum.
First of all, many compliments for the library, it's great!!!
Coming to my question. I found another discussion (closed) about this topic but no hepful informations for me.
I have an json datasource like:
var tableData = {
"data":[
{
"descmedia":"QWERTY",
"codmediaroot":"QWE001",
"fatt":1234.567,
.....
"cost":5678.99516296387,
.....
},
{
"descmedia":"ASDFG",
"codmediaroot":"ASD001",
"fatt":4321.678,
.....
"cost":8765.89273469424,
.....
},
{
"descmedia":"ZXXCV",
"codmediaroot":"ZXX001",
"fatt":9876.554,
.....
"cost":7890.98437654499,
.....
}
]
}
and an array of objects defining my columns:
var columns =
[
/* 0 */ { 'title': 'KeyCode', 'type': 'string', 'data': 'codmediaroot' },
/* 1 */ { 'title': 'Description', 'type': 'string', 'data': 'descmedia' },
.......
/* 9 */ { 'title': 'Cost', 'type': 'curr', 'precision': '2', 'data': 'cost', 'render': function (data, type, row) { return formatNumber(data, type, row, 2, false, true); } },
.......
/* 11 */ { 'title': 'Fatt', 'type': 'curr', 'precision': '2', 'data': 'fatt', 'render': function (data, type, row) { return formatNumber(data, type, row, 2, false, true); } },
.......
];
function "formatNumber" is defined as follows:
function formatNumber ( data, type, row, precision, isPercentage, isCurrency )
{
// do something
}
This is how i initialize the datatable:
var statsTable = jQuery('#report_table').DataTable
(
{
"data": tableData,
"columns": columns,
"orderCellsTop": true,
"scrollX": true,
"scrollY": 400,
"scrollCollapse": true,
"paging": false,
"searching": false,
"bInfo" : false,
}
);
So, as you can see, I have all needed informations to be passed to "formatNumber" in the column definition (type, precision), but I can't find a way to access these informations in the "render" function.
I already use those informations (column properties) also in other functions in the script, so i need them both as properties and (for now) as static parameters.
I think that defining "styling" informations in the column is a way to let the code be more readable rather than specifying those informtions as static function paramaters, duplicating informations.
Is there a way to access column properties from within this function.
Many thanks in advance!
Replies
No one can help me with this question?
Best regards
Unfortunately no - there isn't at the moment. This is something that I plan to address in future, but at the moment you would need to get that information into the function in a different way.
Thanks,
Allan
Thanks a lot anyway!
Marco