dataTable运用

var config = {
    "oLanguage":{
        "sLengthMenu" : "每页显现 _MENU_ 条",
        "sZeroRecords" : "对不起,没有婚配的数据",
        "sInfo" : "第 _START_ - _END_ 条 / 共 _TOTAL_ 条数据",
        "sInfoEmpty" : "没有婚配的数据",
        "sInfoFiltered" : "(数据表中共 _MAX_ 条纪录)",
        "sProcessing" : "正在加载中...",
        "sSearch" : "全文搜刮:",
        "oPaginate" : {
            "sFirst" : "第一页",
            "sPrevious" : " 上一页 ",
            "sNext" : " 下一页 ",
            "sLast" : " 末了一页 "
        }
    },
    "transColumns": [
        {"mData" : "date"},
        { "mData": "description" },
        { "mData": "amt" },
        { "mData": "result" }
    ]
}

var transDetail = function(){
//按钮组
$("#JselBtns").on("click",".btn",function(){
    $(this).siblings().removeClass("active");
    $(this).addClass("active");
    $table.destroy();
    getTransList();
});
function getSearchParam(){
    var searchParam={};
    var searchCon = $("#JselBtns").find(".active").data("search");
    searchParam["type"] = searchCon;
    return searchParam;
}
function getTransList(){
    var transDetailUrl = config.transDetail;
    var _data=getSearchParam();
    $table = $('#ck_table').DataTable({
        "oLanguage" :config.oLanguage,
        "searching": false,
        "ordering":  false,
        "processing": true,
        fnRowCallback:function( row, data, displayIndex, displayIndexFull){
            $('td:first',row).html(new Date(parseInt(data.date)).Format("yyyy-MM-dd"));
            if(data.result == 0){//生意业务胜利
                $('td:eq(3)',row).html("生意业务胜利");
            }else if(data.result == 1){
                $('td:eq(3)',row).html("生意业务失利");
            }else{
                $('td:eq(3)',row).html("正在生意业务中");
            }
            if(data.type == 1){
                $('td:eq(2)',row).html('<strong class="orange-txt">-'+$("td:eq(2)",row).html()+'</strong>');
            }else{
                $('td:eq(2)',row).html('<strong class="green-txt">+'+$("td:eq(2)",row).html()+'</strong>');
            }
        },
        "serverSide": true,
        "ajax": {
            url : transDetailUrl,
            data:{searchConditions : JSON.stringify(_data)},
            type:"get"
        },
        "aoColumns" : config.transColumns,
        "dom": 'rt<"page-bottom clearfix"lip>'
    });
}
return{
    init:function(){
        getTransList();
    }
}
}();
    原文作者:dada86
    原文地址: https://segmentfault.com/a/1190000009178828
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞