How to plot header dynamically by jquery in datatables
How to plot header dynamically by jquery in datatables
mi6crazyheart
Posts: 2Questions: 0Answers: 0
Hey Guys, i'm a new user of datatables & stuck at one point..
I'm using JSON for sending data to datatables. My JSON data format is like this..
[code]
{"aaData":[["91c3ad50d6b10763d9425f9c9eac5ad9","2000-11-14 00:00:00","SUZLON","1196.45","2007-08-06 00:00:00","1199"],["ff3f0deceebaccfc11f87250422956c2","2010-12-30 00:00:00","HEROHONDA","759","2008-12-01 00:00:00","759.95"],["1498e6be95a9715f8fbec111f7d83a51","2005-02-08 00:00:00","RELCAPITAL","46.3","2001-08-30 00:00:00","46.5"],["0836e881131be2bdfaf77cf03fc9e62b","2009-11-27 00:00:00","ACC","358.45","2005-03-28 00:00:00","360.4"],["12dc7222097302cab0bd883e35c2846f","2000-10-17 00:00:00","ACC","180.55","2001-02-01 00:00:00","179.5"]],"aaHeader":["user_id","reco_date","ticker","reco_price","curr_timestamp","curr_mkt_price"]}
[/code]
I'm sending my table header(aaHeader) with JSON data. So, what i want now is to plot those table headers dynamically in datatables.
Right now, i'm trying to use this "fnServerData" callback function to plot the header but it's not working properly. It seems header has overwritten. My code of fnServerData is like this...
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success" : function(jsonData) {
var table_headders = jsonData.aaHeader;
$.each(table_headders, function (i, elem){
console.log(elem);
var tbl_th = '' + elem + ''
$('#tableHeadder').append(tbl_th);
});
fnCallback(jsonData);
}
} );
}
// My Table Header part:
[/code]
So Guys, want some light to move ahead.
Thx in advance... :)
I'm using JSON for sending data to datatables. My JSON data format is like this..
[code]
{"aaData":[["91c3ad50d6b10763d9425f9c9eac5ad9","2000-11-14 00:00:00","SUZLON","1196.45","2007-08-06 00:00:00","1199"],["ff3f0deceebaccfc11f87250422956c2","2010-12-30 00:00:00","HEROHONDA","759","2008-12-01 00:00:00","759.95"],["1498e6be95a9715f8fbec111f7d83a51","2005-02-08 00:00:00","RELCAPITAL","46.3","2001-08-30 00:00:00","46.5"],["0836e881131be2bdfaf77cf03fc9e62b","2009-11-27 00:00:00","ACC","358.45","2005-03-28 00:00:00","360.4"],["12dc7222097302cab0bd883e35c2846f","2000-10-17 00:00:00","ACC","180.55","2001-02-01 00:00:00","179.5"]],"aaHeader":["user_id","reco_date","ticker","reco_price","curr_timestamp","curr_mkt_price"]}
[/code]
I'm sending my table header(aaHeader) with JSON data. So, what i want now is to plot those table headers dynamically in datatables.
Right now, i'm trying to use this "fnServerData" callback function to plot the header but it's not working properly. It seems header has overwritten. My code of fnServerData is like this...
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success" : function(jsonData) {
var table_headders = jsonData.aaHeader;
$.each(table_headders, function (i, elem){
console.log(elem);
var tbl_th = '' + elem + ''
$('#tableHeadder').append(tbl_th);
});
fnCallback(jsonData);
}
} );
}
// My Table Header part:
[/code]
So Guys, want some light to move ahead.
Thx in advance... :)
This discussion has been closed.