bootstrap-table前端修改數據

  使用bootstrap-table顯示數據,後臺傳回數據之後,可能須要對其作調整,如須要前端爲數據添加單位前端

調整數據代碼

$("#"+tableId).bootstrapTable({
        dataType: "json",
        method: 'get',
        contentType: "application/x-www-form-urlencoded",
        cache: false,
        url:url,
        sortName:sortName,  //排序列名
        sortOrder: sortOrder,//排位命令(desc,asc)
        queryParams: queryParams,
        columns:columns,
        pagination:true,
        sidePagination:'server',
        pageNumber:1,
        pageSize:10,
        pageList:[10],       
        onLoadSuccess:function(data){
            //經過對data判斷
            if("rate" in data["rows"][0]){
                var result = data["rows"];
                $.each(result,function(index,content){
                    content["rate"] =content["rate"]+"%";ze5year"] =content["authorize5year"]+"%";
                })
                $("#"+tableId).bootstrapTable("load",data)
            }
        },

代碼的解釋

數據經過onLoadSuccess返回,此時數據已經渲染到頁面中,這裏將返回的數據對應的列中加上相應的單位(「%」)以後,使用json

$("#"+tableId).bootstrapTable("load",data)從新加載到表格中,數據即得以改變
相關文章
相關標籤/搜索