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返回,此时数据已经渲染到页面中,这里将返回的数据对应的列中加上相应的单位(“%”)之后,使用

$("#"+tableId).bootstrapTable("load",data)重新加载到表格中,数据即得以改变