bootstrap editable初始化后表单可修改数据

function loadData() {
    var url = "${ctx }/sys/marketing/product/page";
    $('#tablepager').bootstrapTable({
        url: url,
        dataType: "json",
        pagination: true, //分页
singleSelect: true,//只能选择一行
clickToSelect: true,
        search: false, //显示搜索框
sidePagination: "server", //服务端处理分
pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 50, 100],
        queryParams:function(params){
            var par={"markingCode":$("#searchmarkingCode").val(),"markingName":$("#searchMarkingName").val(),"productCode":$("#searchproductCode").val(),"productName":$("#searchProductName").val(),"productType":$("#searchproductType").val(),};
            var p= $.extend({},params,par);
            return p;
        },
        showColumns: true,
        showRefresh: true,
        showToggle: true,
        toolbar: "#tableToolbar",
        onEditableSave: function (field, row, oldValue, $el) {
            $.ajax({
                type: "post",
                url: "${ctx }/sys/marketing/product/" + row.id,
                data:{ "_method": "put","id":row.id,"markingName":row.markingName,"productType":row.productType,
                    "markingPrice":row.markingPrice,"productName":row.productName,"markingCode":row.markingCode,
                    "productCode":row.productCode},
                dataType: 'JSON',
                success: function (data, textStatus, jqXHR) {
                    layer.msg("编辑成功", {icon: 7});
                },
                error: function () {
                    layer.msg("error", {icon: 7});
                },
                complete: function () {

                }
            });
        },
        columns: [{
            checkbox: true
},
            {
                field : "markingCode",
                title : "活动编码"
}
            ,
            {
                field : "markingName",
                title : "活动名称"
}
            ,
            {
                field : "productCode",
                title : "产品编码"
}
            ,
            {
                field : "productName",
                title : "产品名称"
}
            ,
            {
                field : "markingPrice",
                title : "活动价格(¥)",
                editable: {
                    type: 'text',
                    title: '活动价格(¥)',
                    validate: function (v) {
                        if ($.trim(v) == '') {
                            return '活动价格不能为空!';
                        }
                        if (isNaN(v)) {
                            return '活动价格必须是数字';
                        }
                        var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
                        if(!reg.test(v)) {
                            return '请输入正确的价格';
                        }
                    },
                }
            }
            ,
            {
                field : "productType",
                title : "产品类型",
                formatter: function (value) {
                    switch (value) {
                        case 1:
                            return "门票";
                        case 2:
                            return "酒店";
                        case 3:
                            return "餐饮";
                        case 4:
                            return "普通商品";
                        default:
                            return "-";
                    }
                }
            }
        ],
    });
}
posted @ 2019-08-29 16:53  那些年的代码  阅读(908)  评论(0编辑  收藏  举报