DataTable Refresh Table Header

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.