Data table rendering
Data table rendering
smartpradeep
Posts: 2Questions: 0Answers: 0
I have a JSON data structure like this comes from server side:
[code]
"data":[
{ "subdata":{ "type":"RY", "config":{ "cash":200} }
{ "subdata":{ "type":"SR", "config":{ "cash":200,"chips":300} }
{ "subdata":{ "type":"SR", "config":{ "chips":300} }
{ "subdata":{ "type":"RY", "config":{ "bonus":200,"chips":400} }
{ "subdata":{ "type":"SR", "config":{ "bonus":100} }
]
[/code]
It renders into table in the view like this:
[code]
RY cash=200, Mode Amount=200
SR cash=200,chips=300, Mode Amount=300
SR chips=100, Mode Amount=200
RY bonus=200,chips=400,
SR chips=600, Mode Amount=600
[/code]
While rendering the data,
first column data should give type=RY/SR, but the first cell is coming null after throwing warning like [quote]"DataTables warning (table id = 'table-configs'): Requested unknown parameter 'subdata.type' from the data source for row 0"[/quote] ,
second column data should give the config object , but the second cell is coming null after throwing warning like [quote]"DataTables warning (table id = 'table-configs'): Requested unknown parameter 'subdata.config' from the data source for row 0"[/quote] ,
for the third column rendering data is working.
The dataTable js code is:
[code]
function renderAmount(o, config){
var amount = '';
$.each(config, function(key, value){
amount += key + '=' + value + ',';
});
return amount;
}
function renderGameMode(o, data){
var game_mode= (data.type=='RY')? 'cash' : 'chips';
var mode_value='';
$.each(data.config, function(key,value){
if(key == game_mode){
mode_value = "Mode Amount="+data.config.key;
}
});
return mode_value;
}
$('#table-configs').dataTable({
'aaData': data,
'bPaginate': false,
'aoColumns':[
{ 'mDataProp': 'subdata.type' },
{ 'mDataProp': 'subdata.config',
'fnRender': renderAmount },
{ 'mDataProp': 'subdata',
'fnRender': renderGameMode }]
});
[/code]
[code]
"data":[
{ "subdata":{ "type":"RY", "config":{ "cash":200} }
{ "subdata":{ "type":"SR", "config":{ "cash":200,"chips":300} }
{ "subdata":{ "type":"SR", "config":{ "chips":300} }
{ "subdata":{ "type":"RY", "config":{ "bonus":200,"chips":400} }
{ "subdata":{ "type":"SR", "config":{ "bonus":100} }
]
[/code]
It renders into table in the view like this:
[code]
RY cash=200, Mode Amount=200
SR cash=200,chips=300, Mode Amount=300
SR chips=100, Mode Amount=200
RY bonus=200,chips=400,
SR chips=600, Mode Amount=600
[/code]
While rendering the data,
first column data should give type=RY/SR, but the first cell is coming null after throwing warning like [quote]"DataTables warning (table id = 'table-configs'): Requested unknown parameter 'subdata.type' from the data source for row 0"[/quote] ,
second column data should give the config object , but the second cell is coming null after throwing warning like [quote]"DataTables warning (table id = 'table-configs'): Requested unknown parameter 'subdata.config' from the data source for row 0"[/quote] ,
for the third column rendering data is working.
The dataTable js code is:
[code]
function renderAmount(o, config){
var amount = '';
$.each(config, function(key, value){
amount += key + '=' + value + ',';
});
return amount;
}
function renderGameMode(o, data){
var game_mode= (data.type=='RY')? 'cash' : 'chips';
var mode_value='';
$.each(data.config, function(key,value){
if(key == game_mode){
mode_value = "Mode Amount="+data.config.key;
}
});
return mode_value;
}
$('#table-configs').dataTable({
'aaData': data,
'bPaginate': false,
'aoColumns':[
{ 'mDataProp': 'subdata.type' },
{ 'mDataProp': 'subdata.config',
'fnRender': renderAmount },
{ 'mDataProp': 'subdata',
'fnRender': renderGameMode }]
});
[/code]
This discussion has been closed.
Replies
Btw - I would very strongly recommend against the use of fnRender and use mRender instead :-)
Allan
[code]
$('#table-configs').dataTable({
'sAjaxDataProp': data.data,
'bPaginate': false,
'bDestroy':true,
'aoColumns':[
{ 'mData': 'subdata.type','aTargets':[0]},
{ 'mData': 'subdata.config','aTargets':[1],
'mRender': renderAmount },
{ 'mData': 'subdata','aTargets':[2],
'mRender': renderGameMode }]
});
[/code]