bootstrap table 第一弹:实现模态框弹出编辑

布局代码:

效果图:

分享图片

分享图片

 

<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="/static/bootstrap-table/bootstrap-table.css">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <script src="/static/bootstrap-table/bootstrap-table.js"></script>
    <script src="/static/bootstrap-table/locals/bootstrap-table-zh-CN.js"></script>
    <!--<script src="https://unpkg.com/tableexport.jquery.plugin/tableExport.min.js"></script>-->
    <!--<script src="https://unpkg.com/[email protected]/dist/extensions/export/bootstrap-table-export.min.js"></script>-->
    <title>数据表</title>
    <style>
    </style>
</head>
<body>
<div id="toolbox">
    <button class="btn" ><span class="glyphicon glyphicon-plus"></span> 新增</button>
    <button class="btn" id="edit_table_btn"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>
    <button class="btn"><span class="glyphicon glyphicon-remove"></span> 删除</button>
</div>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="myModal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">编辑报价单</h4>
            </div>
            <div class="modal-body">
                <form action="" class="form-horizontal">
                    <div class="form-group">
                        <input type="hidden" class="form-control" disabled="disabled" id="modal_id">
                        <label for="" class="col-sm-2 control-label">报价单号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" disabled="disabled" id="modal_bj_no">
                        </div>
                    </div>
                     <div class="form-group">
                        <label for="" class="col-sm-2 control-label">客户</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="modal_cus_name">
                        </div>
                    </div>
                     <div class="form-group">
                        <label for="" class="col-sm-2 control-label">报价产品</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="modal_bj_prd">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label" >单价</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="modal_up">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label" >模具成本</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="modal_mj_cst">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="sava-edit-btn">保存</button>
            </div>
        </div>
    </div>
</div>


<table id="mytable"></table>
</body>
</html>

javascript代码:

<script>
    /* * 总结: * 解决的问题点:以下$table = $(bootstrapTable) 对象 * 1.使用bootstrap table 显示数据,实现点击 [编辑] 按钮,弹出模态框,并把该行的数据显示在模态框中。 * 知识点1:js触发模态框显示,$("myModal").modal() * 知识点2:使用getSelections获取到,bootstrap table选中的行的数据。info = $table.bootstrapTable("getSelections")[0],获取到的是一个json数据,格式[{.....}] * 知识点3:页面向模态框传值,其实模态框本身就是在页面上,只是被隐藏了,所有直接用$("模态框输入框选择器").val(表单里面的值) * 知识点4:编辑的模态框的值传回table,这里用到 bootstrapTable的updateRow,调用方式 * $table.bootstrapTable(‘updateRow‘,{ * index:index,* row:{ * id:new_id,* name:new_name,* ... * } * }) * 知识点5:我们发现上面的编辑需要用到行号,但是在getSelections中并不包含行号的信息,所有我们需要单独的找到当前编辑的行的行号。然后就有了下面的代码: * onClickRow:function(row,$e){ * index = $e.data(‘index‘); * },* */

    var $table = $("#mytable"); var index= ‘‘; $table.bootstrapTable({ //url:"https://examples.wenzhixin.net.cn/examples/bootstrap_table/data",
        url: ‘get_json/‘,sortable: true,search: true,pagination: ‘true‘,//开启分页
        toolbar: "#toolbox",singleSelect: true,showColumns: true,clickToSelect: true,showRefresh: true,//下面onClickRow为点击该行的时候获取到该行的行号; 在外边设置index,当点击某一行的时候,再改写该值。
        onClickRow:function(row,$e){ index = $e.data(‘index‘); },//sidePagination:‘server‘,//分页处理 ??
        idField:‘id‘,columns: [{checkbox: true},{ field: ‘id‘,title: ‘ID‘,},/*{ //这一段为为一行增加序号,但是在getSelections里面获取不到值,尽管有设置field:‘index‘。 field:‘index‘,title:‘序号‘,formatter:function (value,row,index) { var options = $table.bootstrapTable(‘getOptions‘); return options.pageSize * (options.pageNumber - 1) + index + 1;} },*/{ field: ‘bj_no‘,title: ‘报价单号‘,{ field: ‘cus_name‘,title: "客户",{ field: ‘bj_prd‘,title: "报价产品",{ field: ‘up‘,title: "单价",{ field: ‘mj_cst‘,title: "模具成本",}],}); var $editbtn = $("#edit_table_btn"); $(function () { $editbtn.click(function () { var info = $table.bootstrapTable(‘getSelections‘)[0]; if(info.length==2){ alert("请选择数据"); }else{ $("#modal_id").val(info.id) $("#modal_bj_no").val(info.bj_no) $("#modal_cus_name").val(info.cus_name) $("#modal_bj_prd").val(info.bj_prd) $("#modal_up").val(info.up) $("#modal_mj_cst").val(info.mj_cst) $("#myModal").modal(); } }); /* //获取点击的行的行号 有效:为获得编辑的行号的尝试。 $table.on("click-row.bs.table",function(e,$element) { var index= $element.data(‘index‘); alert(index); }); */

        //关闭模态框数据保存到table
        $("#sava-edit-btn").click(function () { $(‘#myModal‘).modal(‘hide‘); var id = $("#modal_id").val(); var new_cus_name = $("#modal_cus_name").val(); var new_bj_prd = $("#modal_bj_prd").val(); var new_up = $("#modal_up").val(); var new_mj_cst = $("#modal_mj_cst").val(); $table.bootstrapTable("updateRow",{ index:index,row:{ id:id,cus_name:new_cus_name,bj_prd:new_bj_prd,up:new_up,mj_cst:new_mj_cst } }); }) }) </script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


前端工程师一般用的是Bootstrap的框架而不是样式,样式一般自己重新定义class类即可,主要样式要随具体情况而定包括位置任何带有class.btn的元素都会继承圆角灰色按钮的默认外观。但是Bootstrap提供了一些选项来定义按钮的样式。<buttontype="button"class="btn">基本
起步导入:<linkrel="stylesheet"href="bootstrap-3.3.7-dist/css/bootstrap.css"><scriptsrc="js/jquery-3.3.1.js"></script><scriptsrc="bootstrap-3.3.7-dist/js/bootstrap.js"></script>屏幕
(1)modal声明一个模态框(2)modal-dialog定义模态框尺寸(3)modal-lg定义大尺寸模态框(4)modal-sm定义小尺寸模态框(5)modal-header(6)modal-body(7)modal-footer<!doctypehtml><html><head><metacharset="utf-8"><title>模态框<itle><linkrel=&quo
图片在Bootstrap版本3中,通过为图片添加 .img-responsive 类可以让图片支持响应式布局。其实质是为图片设置了 max-width:100%;、 height:auto; 和 display:block; 属性,从而让图片在其父元素中更好的缩放。如果需要让使用了 .img-responsive 类的图片水平居
<inputtype="text"class="form-controldatepicker"style="padding:0.375rem0.75rem;"placeholder="开始时间"readonly="true" id="start_time"name="start_time"> $(".datepicke
目录bootstrap-treeview使用小记零、写在前面的话一、功能说明二、特性简述三、实战3.1依赖环境3.2数据源格式3.3Options选项3.4Methods方法3.5Events事件N-2、番外N-1、本文demoN、参考资料bootstrap-treeview使用小记零、写在前面的话p.s.bootst
  一、应用http://www.bootcss.com/进入bootstrap4或bootstrap3中文网,想要快速地将Bootstrap应用到你的项目中,有以下两种办法: 1、bootstrap可以在线引用,方法如下:A、CSS将引入Bootstrap样式表的 <link> 标签复制并粘贴到 <head> 中,并放在所有其他样式表之前。<!
第87节:Java中的Bootstrap基础与SQL入门前言复习什么是JQ?:writelessdomore写更少的代码,做更多的事找出所有兄弟:$("div").siblings()基本过滤器:选择器:过滤器$("div:first"):first:找到第一个元素:last:找到最后一个元素:even:找出偶数索引:odd:找出奇叔索引
1.bootstrap表单(1)form声明一个表单域(2)form-inline内联表单域(3)form-horizontal水平排列表单域(4)form-group表单组、包括表单文字和表单控件(5)form-control文本输入框、下拉列表控件样式(6)checkboxcheck-inline多选框样式(7)radioradio-inline单选框样式(8)input-group表单控件组
<!DOCTYPEhtml><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>首页<itle><
嗯。。。以前做ssh。应该是stratusspringhibernate。 然后现在来了一个新的需求。 要用java,bootstrap,oracle,springboot,jquery,mybatis。 开始,我也挺心虚的,但是后来一看,,,其实本没有必要这么虚。。。毕竟。。。这些东西,写的有问题。。。问题在于没有逻辑。 bootstrap,j
表格基本实例为任意 <table> 标签添加 .table 类可以为其赋予基本的样式—少量的内补(padding)和水平方向的分隔线。这种方式看起来很多余!?但是我们觉得,表格元素使用的很广泛,如果我们为其赋予默认样式可能会影响例如日历和日期选择之类的插件,所以我们选择将此样式独立出来。
1、问题背景   一般情况下,查询列表有查询条件、查询按钮和重置按钮,输入查询条件,点击查询按钮查询列表等数据;点击重置按钮会将查询条件恢复到原始状态 2、实现源码 <!DOCTYPEhtml><html> <head> <metacharset="UTF-8"> <title>Bootstrap-查询按钮和重置按钮<
Bootstrap简介什么是Bootstrap?Bootstrap官网框架:库liblibraryjQuery作为一个框架来讲,提供一套比较便捷的操作DOM的方式把大家都需要的功能预先写好到一些文件这就是一个框架Bootstrap让我们的Web开发更简单,更快捷;注意是Bootstrap不是BootStrap!这是一个词,不是
1.bootstrap图片img-responsive声明响应式图片2.bootstrap字体图标通过字体代替图标,font文件夹需要和css文件夹在同一目录3.bootst导航条(1)navbar声明导航条(2)navbar-default声明默认的导航条样式(3)navbar-inverse声明反白的导航条样式(4)navbar-static-top去掉导航条的圆角(5)n
1.路径导航<!doctypehtml><html><head><metacharset="utf-8"><title>路径导航<itle><linkrel="stylesheet"type="text/css"href="css/bootstrap.min.css"><scripttype="text/ja
问题描述:最近在学习BootStrap,过程中遇到引用glyphicon图标无法显示的问题,经过在百度后该问题已解决。1、首先看一下图标显示失败的页面:2、经过参考大佬们的经验,我找到了解决办法。首先我的BootStrap的css样式表是经过下载之后直接拷贝了其中一个文件到编译器中使用的,没有把所有
BootStrap布局一、BootStrap布局CSS组件主要包括栅格系统、列表组、进度条、icon图标、导航栏等组件。JavaScript插件主要有动画效果、窗体模式、下拉菜单、选项卡等二、网格系统Bootstrap内置了一套响应式、移动优先的流式栅格系统,随着屏幕设备或可视窗口(viewport)尺寸的
1引入所需要的文件2用法
想让bootstrap的table列内容超出部分省略号,要在table上加table-layout:fixed和word-break:break-all,然后在头部thead的th加上宽度百分比,最后在列里加个标签如span,在这个span加上单行超出部分省略号的css:display:inline-block,overflow:hidden,white-space:nowrap,text-overflow:e