Data table rendering

Data table rendering

smartpradeepsmartpradeep Posts: 2Questions: 0Answers: 0
edited September 2012 in General
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]

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Should the parameter you are passing in for aaData perhaps be data.data?

    Btw - I would very strongly recommend against the use of fnRender and use mRender instead :-)

    Allan
  • smartpradeepsmartpradeep Posts: 2Questions: 0Answers: 0
    edited September 2012
    Can u please sample the code once...cause when i am rendering the data showing no rows
    [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]
This discussion has been closed.