zoukankan      html  css  js  c++  java
  • 前端开发

    使列可修改

                {field: 'reason', title: '申请原因', align: 'center',
                    formatter: function (value, row, index) {
                        return '<input type="text" id="reason" data-index="'+index+'" onchange="changeReason(this)" value="'+value+'" />'
                    }
                }
    

    被修改后触发的监听事件:

        function changeReason(e) {
            var value = $(e).val();
            var index = $(e).attr("data-index");
            dataList[index].reason = value;
        }
    

    其中dataList是一个全局变量

        var dataList = []; 
    

    在数据加载成功时为其赋值:

            onLoadSuccess: function(){
                dataList = $table.bootstrapTable("getData", true);
                if(type == 2){
                    $table.bootstrapTable('hideColumn', 'abstractName');//隐藏abstractName列
                }else {
                    $('#table').bootstrapTable('showColumn', 'abstractName');
                }
            }
    

    提交动作:

        function saveOrSubmit(type) {
            $.ajax({
                type: "post",
                url: "/admin/warning/apply/save",
                data: {
                    saveType: type,
                    dataListStr: JSON.stringify(dataList),
                    bzy: $("#bzy").val(),
                    kj: $("#kj").val(),
                    cn: $("#cn").val(),
                },
                dataType: "json",
                success: function (msg) {
                    // msg = JSON.parse(msg);
                    console.log(msg);
                    if (msg.code == 0) {
                        layer.msg(msg.message, {icon: 1, time: 2000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(msg.message, {icon: 2, time: 2000})
                    }
                }
            });
        }
    

    完整代码:

        var dataList = []; 
        var $table = $('#table');
        var type = '${type}';
        $table.bootstrapTable({
            method: "POST",
            url: "${ctx!}/admin/warning/apply/getConfirmCostApplicationList/" + type,
            contentType: "application/x-www-form-urlencoded",
            striped: true,
            pagination: true, 
            pageSize: 1000,
            pageList: [1000],
            pageNumber: 1,
            sidePagination: "server",
            queryParamsType: "undefined",
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            height: $(window).height() * 0.58,
            responseHandler: function (res) {
                return {
                    "rows": res.content,
                    "total": res.totalElements,
                };
            },
            columns: [
                {field: 'subjectCode', title: '科目代码', align: 'center',},
                {field: 'subject', title: '科目名称', align: 'center',},
                {field: 'abstractName', title: '摘要', align: 'center',},
                {field: 'limitAmount', title: '限制金额', align: 'center',},
                {field: 'appliedAmount', title: '申请金额', align: 'center',},
                {field: 'reason', title: '申请原因', align: 'center',
                    formatter: function (value, row, index) {
                        return '<input type="text" id="reason" data-index="'+index+'" onchange="changeReason(this)" value="'+value+'" />'
                    }
                }
            ],
            onLoadSuccess: function(){
                dataList = $table.bootstrapTable("getData", true);
                if(type == 2){
                    $table.bootstrapTable('hideColumn', 'abstractName');
                }else {
                    $('#table').bootstrapTable('showColumn', 'abstractName');
                }
            }
        });
    
        function changeReason(e) {
            var value = $(e).val();
            var index = $(e).attr("data-index");
            dataList[index].reason = value;
        }
    
        function saveOrSubmit(type) {
            $.ajax({
                type: "post",
                url: "/admin/warning/apply/save",
                data: {
                    saveType: type,
                    dataListStr: JSON.stringify(dataList),
                    bzy: $("#bzy").val(),
                    kj: $("#kj").val(),
                    cn: $("#cn").val(),
                },
                dataType: "json",
                success: function (msg) {
                    console.log(msg);
                    if (msg.code == 0) {
                        layer.msg(msg.message, {icon: 1, time: 2000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(msg.message, {icon: 2, time: 2000})
                    }
                }
    
            });
        }
    
  • 相关阅读:
    跨公司销售利润中心替代
    [WCF学习笔记] 我的WCF之旅(1):创建一个简单的WCF程序
    linux操作常用命令
    java lambda表达式
    关于lock和synchronized的选择
    ssh免密登陆(简单快捷)
    su和sudo的区别
    Linux常用查找命令
    vmware完整克隆(linux)
    springboot2.0拦截器和webconfigure配置
  • 原文地址:https://www.cnblogs.com/zhangnianlei/p/12239260.html
Copyright © 2011-2022 走看看