Creating columns dynamically with Datatables Jquery -


i using datatables server_processing data, main issue dont want specify name of columns in html (<th width="25" id ="th1">id</th>), want create columns dynamically when getting data ajax.

my code :

$('#table').datatable( {      "bprocessing": true,     "bserverside": true,     "sajaxsource": "server_processing.php?db="+pid+"&table="+id+"", //pid name of database , id name of table      "bjqueryui": true,     "spaginationtype": "full_numbers"  } );              

"although datatables can obtain information table directly dom, may wish give datatables specific instructions each individual column. can done using either aocolumndefs parameter, or aocolumns , object information given each column."http://datatables.net/usage/columns

something like:

html

<table class="display" id="table"></table> 

js

$("#table").datatable({     bjqueryui:true,     aocolumns:[         {mdataprop:"foo",stitle:"foo title"},         {mdataprop:"bar",stitle:"bar title"}     ],     fnserverdata: function( surl, data, fncallback){         $.get('data.php', function(res) {             fncallback({  // process results match table format                 "secho":config.secho,                 "itotalrecords":res.data.total || res.data.count,                 "itotaldisplayrecords":res.data.count || res.data.total,                 "aadata":res.data.list             })         });     } }) 

where data.php is

{     data:{         total:200,         count:3,         list:[             {foo:"foo 1",bar:"bar 1"},             {foo:"foo 2",bar:"bar 2"},             {foo:"foo 3",bar:"bar 3"},         ]     } } 

there's summary of setting here: http://datatables.net/usage/options#aadata


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -