bootstrap 动态列展示(后台数据js处理行转列)

var columns = new Array();
    var retdata = {};
    var colData = new Array();
    var moneyCol = {"name":"金额"};
    var numCol = {"name":"人数"};
    var json = {};
    $.getJSON("../../eldercare/statisticalreport/getBaseServiceOldman1?_" + $.now(), function(r) {
        retdata = r;
        columns.push({field : "name", title : "会员类型", width : "100px"});
        retdata.forEach(function(value,index,array){
            if(value.type == 'total'){
                value.type = '共计';
            }else if(value.type == 'cancel'){
                value.type = '注销';
            }
            columns.push({field :value.type, title :value.type, width : "100px"});
            moneyCol[value.type]= value.amount;
            numCol[value.type]= value.peoplenum;
        });
        colData.push(numCol);
        colData.push(moneyCol);
        json.rows = colData;
        $('#dataGrid0').bootstrapTableEx({
            columns:columns
            // columns: [
            //     {field : "name", title : "会员类型", width : "100px"},
            //     {field : "a1", title : "A1", width : "100px"},
            //     {field : "a2", title : "A2", width : "100px"},
            //     {field : "b1", title : "B1", width : "100px"},
            //     {field : "b2", title : "B2", width : "100px"},
            //     {field : "total", title : "共计", width : "100px"},
            //     {field : "cancel", title : "注销", width : "100px"},
            // ]
        });
        $('#dataGrid0').bootstrapTable('load',json);
    });

你可能感兴趣的:(bootstrap 动态列展示(后台数据js处理行转列))