Generate tabular data using the jquery DataTable, call Table.fndestroy () when the table header needs to be changed, and then recreate the table header
varotable =NULL;functioninitsettings () {varcolumns = []; $.ajax ({type:"POST", URL:"${ctx}/getdynamiccolumns", DataType:"JSON", Data: $ ("#query_form"). Serialize (), Async:false, Success:function(data) {Columns.push ({"Stitle": "Date", "Mdata": "Createtime", "SName": "Createtime", "Swidth": "120", }); Columns.push ({"Stitle": "Merchant Full Name", "Mdata": "FullName", "SName": "FullName", "Swidth": "100", }); Columns.push ({"Stitle": "Merchant abbreviation", "Mdata": "ShortName", "SName": "ShortName", "Swidth": "100", }); / * Here is actually a dynamic column, query to the desired column, and then generate * /$.map (data,function(Item,index) {console.log (Item.stitle) Columns.push ({"Stitle": Item.stitle,"Mdata": Item.mdata,"SName": Item.sname,"Swidth": "100", "Mrender":function(data,type,full) {if(Data! =NULL){ returndata; }Else{ return""; } } }); }); Columns.push ({"Stitle": "First-level agents", "Mdata": "Agent1", "SName": "Agent1", "Swidth": "100", "Mrender":function(data,type,full) {if(Data! =NULL&& Data! = ""){ returndata; }Else{ return"No"; } } }); Columns.push ({"Stitle": "Level Two Agents", "Mdata": "Agent2", "SName": "Agent2", "Swidth": "100", "Mrender":function(data,type,full) {if(Data! =NULL&& Data! = ""){ returndata; }Else{ return"No"; } } }); } }); returncolumns;}functioncreatetable () {otable= Createdatatable ("coupon_channel_table", { "Sajaxsource": ' ${ctx}/coupon_channel_statistic/list ', "Aocolumns": Initsettings (),"Fnserverparams":function(params) {varFields = $ (' #query_form '). Serializearray (); $.each (Fields,function(i, field) {if(Field.name &&field.value) {Params.push ({"Name": Field.name, "value": Field.value}); } }); } });}functionloadtable () {if(NULL!=otable) {Otable.fndestroy ();//Destroy Table object $ ("#detail_table_div"). HTML ("<table id= ' coupon_channel_table ' ></table>"); } createtable (); /*if ($ ("#coupon_channel_table"). Find ("TD"). Length = = 0) {createtable (); }else{Otable.fndraw (); } */}
Page Div
< Div ID = "Detail_table_div" > < ID= "coupon_channel_table"></table> </div>
DataTable Refresh Table Header