HTML代码

/*index.cshtml*/

@section styles{
    <style>
        .main {
            margin-top:20px;
        }

        .modal-body .form-group .form-control {
            display:inline-block;
        }
        .modal-body .form-group .tips {
            color:red;
        }
    </style>
}

<div class="main">
    <div id="toolbar" class="btn-group">
        <button id="addProductBtn" type="button" class="btn btn-default" onclick="showAddModal()">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增产品
        </button>
    </div>

    <table id="table"></table>
</div>

<div class="modal fade" id="productModal" tabindex="-1" role="dialog" aria-labelledby="productModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="productModalLabel"></h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="prodId" class="col-md-2">编号:</label>
                    <input type="text" class="form-control" id="prodId" disabled>
                </div>
                <div class="form-group">
                    <label for="prodName" class="col-md-2">名称:</label>
                    <input type="text" class="form-control" id="prodName">
                    <span class="tips" >(最多20个字)</span>
                </div>
                <div class="form-group">
                    <label for="prodTecParam" class="col-md-2">技术参数:</label>
                    <textarea rows=" class="form-control" id="prodTecParam"></textarea>
                    <span class="tips" >(最多150个字)</span>
                </div>
                <div class="form-group">
                    <label for="prodType" class="col-md-2">类型:</label>
                    <select class="form-control" id="prodType">
                        <option value=">普通产品</option>
                        <option value=">明星产品</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="modalSubmitBtn" type="button" class="btn btn-primary">{{modalBtn}}</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

@section scripts{
    <script type="text/javascript" src="~/Scripts/bootstrap-table.js"></script>
    <script type="text/javascript" src="~/Scripts/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript" src="~/Scripts/common.js"></script>
    <script type="text/javascript" src="~/Views/Home/index.js"></script>
}

JS代码

/*index.js*/

$(document).ready(function () {
    var $table = $('#table');
    ;    //技术参数默认折叠显示长度

    $table.bootstrapTable({
        locale: 'zh-CN',
        url: '/product/getList',
        method: 'post',
        contentType: 'application/json',
        dataType: "json",
        toolbar: '#toolbar',                //工具按钮用哪个容器
        pagination: true,
        search: true,
        showRefresh: true,
        sidePagination: "server",           //分页方式:client客户端分页,server服务端分页
        singleSelect: true,                 //单行选择
        pageNumber: ,                      //初始化加载第一页,默认第一页
        pageSize: ,                       //每页的记录行数
        pageList: [, , ],
        queryParams: function (params) {    //请求参数
            var temp = {
                pageSize: params.limit,                      //页面大小
                pageNo: ,    //页码
                search: $('.search input').val()
            };

            return temp;
        },
        responseHandler: function (res) {
            return {
                pageSize: res.pageSize,
                pageNumber: res.pageNo,
                total: res.total,
                rows: res.rows
            };
        },
        columns: [
            {
                title: '产品编号',
                field: 'id'
            },
            {
                title: '产品名称',
                width: ,
                field: 'name'
            },
            {
                title: '技术参数',
                field: 'tecParam',
                width: ,
                formatter: tecParamFormatter,
                events: {
                    "click .toggle": toggleText
                }
            },
            {
                title: '类型',
                field: 'type',
                formatter: typeFormatter
            },
            {
                title: '操作',
                formatter: operateFormatter,
                events: {
                    "click .mod": showUpdateModal,
                    "click .delete": deleteProduct
                }
            }
        ]
    });

    function tecParamFormatter(value, row, index) {
        ) {
            , textLength) + '...</span>&nbsp;<a class="toggle" href="javascript:void(0)">展开</a>';
        }
        return value;
    }

    function toggleText(e, value, row, index) {
        if (value == null) {
            return false;
        }

        var $tecParam = $(this).prev(".tec-param"),
            $toggle = $(this);

        ) { //折叠
            $tecParam.text(value.substr(, textLength) + "...");
            $toggle.text("展开");
        }
         && $tecParam.text().length <= textLength + ) {   //展开
            $tecParam.text(value);
            $toggle.text("折叠");
        }
    }

    function typeFormatter(value, row, index) {
        var type = "";
        ")
            type = "普通产品";
        ")
            type = "明星产品";
        return type;
    };

    function operateFormatter (value, row, index) {
        return '<a class="mod btn btn-info" href="javascript:void(0)">修改</a> '
            + '<a class="delete btn btn-danger" href="javascript:void(0)">删除</a>';
    };

    function showUpdateModal (e, value, row, index) {
        $("#productModalLabel").text("更新产品信息");
        $("#modalSubmitBtn").text("更新");

        $("#prodId").val(row.id);
        $("#prodId").attr("disabled", true);    //禁止修改id
        $("#prodName").val(row.name);
        $("#prodTecParam").val(row.tecParam);
        )
            $("#prodType").find('option[value="1001"]').attr("selected", true);
        )
            $("#prodType").find('option[value="1002"]').attr("selected", true);

        $("#modalSubmitBtn").unbind();
        $("#modalSubmitBtn").on("click", updateProduct);

        $("#productModal").modal("show");
    };

    function deleteProduct (e, value, row, index) {
        var product = {
            id: row.id
        };
        if (product.id === null || product.id === "") {
            return false;
        }

        Common.confirm({
            message: "确认删除该产品?",
            operate: function (result) {
                if (result) {
                    $.ajax({
                        type: "post",
                        url: "/product/delete",
                        contentType: "application/json",
                        data: JSON.stringify(product),
                        success: function (data) {
                            if (data !== null) {
                                if (data.result) {
                                    $("#table").bootstrapTable("refresh", { silent: true });
                                    tipsAlert('alert-success', '提示', '删除成功!');
                                }
                                else {
                                    tipsAlert('alert-warning', '提示', '删除失败!');
                                }
                            }
                        },
                        error: function (err) {
                            tipsAlert('alert-danger', '警告', '服务器异常,请稍后再试!');
                            console.log("error:", err.statusText);
                        }
                    });

                    return true;
                }
                else {
                    return false;
                }
            }
        });
    };

    var $search = $table.data('bootstrap.table').$toolbar.find('.search input');
    $search.attr('placeholder', '请输入编号、产品名称、技术参数搜索');
    $search.css(');

    $(".model .form-group input").on("click", function(){
        $(this).next(".tips").text("");
    });
});

var showAddModal = function () {
    $("#productModalLabel").text("新增产品");
    $("#modalSubmitBtn").text("新增");

    $("#prodId").val('');
    $("#prodName").val('');
    $("#prodTecParam").val('');

    $("#modalSubmitBtn").unbind();
    $("#modalSubmitBtn").on("click", addProduct);

    $("#productModal").modal("show");
};

var addProduct = function () {
    var product = {
        name: $("#prodName").val(),
        tecParam: $("#prodTecParam").val(),
        type: $("#prodType").val()
    };
    if (product.name == null || product.name == "") {
        $("#prodName").next(".tips").text("产品名称不能为空!");
        return false;
    }
    ) {
        $("#prodName").next(".tips").text("最多20个字!");
        return false;
    }
    ) {
        $("#prodTecParam").next(".tips").text("最多150个字!");
        return false;
    }

    $.ajax({
        type: "post",
        url: "/product/add",
        contentType: "application/json",
        data: JSON.stringify(product),
        success: function (data) {
            if (data !== null) {
                if (data.result) {
                    $("#table").bootstrapTable("refresh", { silent: true });
                    $("#productModal").modal('hide');
                    $("#prodId").val('');
                    $("#prodName").val('');
                    $("#prodTecParam").val('');
                    tipsAlert('alert-success', '提示', '新增成功!');
                }
                else {
                    tipsAlert('alert-warning', '提示', '新增失败!');
                }
            }
        },
        error: function (err) {
            tipsAlert('alert-danger', '警告', '服务器异常,请稍后再试!');
            console.log("error:", err.statusText);
        }
    });
};

var updateProduct = function () {
    var product = {
        id: $("#prodId").val(),
        name: $("#prodName").val(),
        tecParam: $("#prodTecParam").val(),
        type: $("#prodType").val()
    };
    if (product.name == null || product.name == "") {
        $("#prodName").next(".tips").text("产品名称不能为空!");
        return false;
    }
    ) {
        $("#prodName").next(".tips").text("最多20个字!");
        return false;
    }
    ) {
        $("#prodTecParam").next(".tips").text("最多150个字!");
        return false;
    }

    $.ajax({
        type: "post",
        url: "/product/update",
        contentType: "application/json",
        data: JSON.stringify(product),
        success: function (data) {
            if (data !== null) {
                if (data.result) {
                    $("#table").bootstrapTable("refresh", { silent: true });
                    $("#productModal").modal('hide');
                    $("#prodId").val('');
                    $("#prodName").val('');
                    $("#prodTecParam").val('');
                    tipsAlert('alert-success', '提示', '修改成功!');
                }
                else {
                    tipsAlert('alert-warning', '提示', '修改失败!');
                }
            }
        },
        error: function (err) {
            tipsAlert('alert-danger', '警告', '服务器异常,请稍后再试!');
            console.log("error:", err.statusText);
        }
    });
};

Bootstrap-table使用记录(转)的更多相关文章

  1. bootstrap table 学习记录

    效果: html代码: <!-- 工具容器 --> <div id="toolbar" class="btn-group"> <b ...

  2. BootStrap table使用

    bootstrap table git address https://github.com/wenzhixin/bootstrap-table 引入文件 <link rel="sty ...

  3. bootstrap Table 中给某一特定值设置table选中

    bootstrap Table 中给某一特定值设置table选中 需求: 如图所示:左边地图人员选定,右边表格相应选中. 功能代码: //表格和图标联动 function changeTableSel ...

  4. JS组件系列——表格组件神器:bootstrap table

    前言:之前一直在忙着各种什么效果,殊不知最基础的Bootstrap Table用法都没有涉及,罪过,罪过.今天补起来吧.上午博主由零开始自己从头到尾使用了一遍Bootstrap Table ,遇到不少 ...

  5. JS组件系列——表格组件神器:bootstrap table(二:父子表和行列调序)

    前言:上篇 JS组件系列——表格组件神器:bootstrap table 简单介绍了下Bootstrap Table的基础用法,没想到讨论还挺热烈的.有园友在评论中提到了父子表的用法,今天就结合Boo ...

  6. JS组件系列——表格组件神器:bootstrap table(三:终结篇,最后的干货福利)

    前言:前面介绍了两篇关于bootstrap table的基础用法,这章我们继续来看看它比较常用的一些功能,来个终结篇吧,毛爷爷告诉我们做事要有始有终~~bootstrap table这东西要想所有功能 ...

  7. JS组件系列——Bootstrap Table 表格行拖拽

    前言:之前一直在研究DDD相关知识,好久没更新JS系列文章了.这两天做了一个简单的业务需求,觉得效果还可以,今天在这里分享给大家,欢迎拍砖~~ 一.业务需求及实现效果 项目涉及到订单模块,那天突然接到 ...

  8. 后台系统组件:一丶bootstrap table

    http://www.cnblogs.com/landeanfen/p/4976838.html (bootstrap table) http://www.cnblogs.com/landeanfen ...

  9. .Net MVC+bootstrap Table学习

    一.效果展示 二.使用方法 1).相关css和js的引用 <link href="~/Themes/Bootstrap/css/bootstrap.css" rel=&quo ...

  10. 161222、Bootstrap table 服务器端分页示例

    bootstrap版本 为 3.X bootstrap-table.min.css bootstrap-table-zh-CN.min.js bootstrap-table.min.js 前端boot ...

随机推荐

  1. Android 性能测试——Heap Viewer 工具

    Android 性能测试--Heap Viewer 工具 Heap Viewer能做什么? 实时查看App分配的内存大小和空闲内存大小 发现Memory Leaks Heap Viewer使用条件 5 ...

  2. OpenCV1.0在VC ++6.0下的配置

    1.本人使用win7操作系统,首先要预装VC++6.0,安装方法不再赘述. 2.在OpenCV官方网站下载OpenCV的安装文件"OpenCV_1.0.EXE"(参考链接:http ...

  3. centos下编译安装Openssl

    yum install -y zlib*mkdir /datacd /data下载好tar包tar zxf openssl-1.0.2g.tar.gzcd openssl-1.0.2g./config ...

  4. NYOJ--46--最少乘法次数

    最少乘法次数 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 给你一个非零整数,让你求这个数的n次方,每次相乘的结果可以在后面使用,求至少需要多少次乘.如24:2*2 ...

  5. 安徽省2016“京胜杯”程序设计大赛_J_YZK的大别墅

    YZK的大别墅 Time Limit: 1000 MS Memory Limit: 65536 KB Total Submissions: 24 Accepted: 12 Description 土豪 ...

  6. 浅谈odoo 后台与前端文件(附件)的存储与下载

    odoo 后台与前端文件(附件)存储与下载实现 笔记太多了很乱,想想还是写博客的好,慢慢更 当然了,前提是你已经配好了odoo开发环境 一.odoo后台界面实现附件的上传和下载 1).在应用中搜索下图 ...

  7. JavaScript 排序算法(JavaScript sorting algorithms)

    JavaScrip 排序算法(JavaScript Sorting Algorithms) 基础构造函数 以下几种排序算法做为方法放在构造函数里. function ArrayList () { va ...

  8. SecureCRT-转换密钥-Xshell-配置服务-使用xshell登录远程linux服务器

    这篇文档不保证正确,仅仅是备份个因为所以,不必当真. SecureCRT和xShell这2个工具功能类似,均可以控制远程服务器模拟并发用户. SecureCRT自带功能可以将私钥转换为xShell可用 ...

  9. 开源社群系统ThinkSNS+PC端最新播报!

    亲爱的粉丝,授权客户,企业创业者们,这一次,我们将为你们打造最好用的社交软件系统. 在这里你将看到TSer们本周研发.优化.设计的动态即时播报,可评论留言提出您的问题及建议与我们互动. 同时,研发已经 ...

  10. python练习题一

    1.使用while循环输出1 2 3 4 5 6     8 9 10 答:i=0 while i<10:     i += 1     if i!=7:         print(i) 2. ...