前端:DataTable通用js

//动态初始化表格,从服务器拿数据  
var id = "0";
var table = $('#list-table').DataTable( {
    "ajax" : {
        "url" : getRootPath()
                + "/data/standard/standard.do?method=GetTableData",
        "data" : function(d) { // d表示上一次请求的对象
        //  return $.extends({}, d, {org_code: 2});
        //                d.id = id; 
            return {
                "id" : id
            };
        },
        "dataSrc" : ""
    },
    "columns" : [ {
        "data" : null,
        "defaultContent" : "<input type='checkbox'>"
    }, {
        "data" : "tag_id"
    }, {
        "data" : "tag_name_cn"
    }, {
        "data" : "tag_meaning"
    }, {
        "data" : "date_time"
    }, {
        "data" : "tag_id"
    } ],
    "columnDefs" : [ {
        "targets" : [ 5 ],
        "render" : function(data, type, full) {
            var text = "<a href='standardcreate.htm?neibubiaoshifu="
                    + data + "'>编辑</a>";
            return text;
        }
    } ]
});

// 此处更新表格数据
$("#debug").click(function() {
    id = "2";
    table.ajax.reload();
})
// 此处刷新数据
$("#debug").click(function() {
    table.ajax.url(
        getRootPath() + 
        "/data/standard/catalog.do?method=GetCatalogStandard"
    ).load();
})
posted @ 2019-01-11 10:43  xuejianbest  阅读(1394)  评论(0编辑  收藏  举报