bootstrapTable 全选 自定义事件使用

bootstrapTable样式实现如下:

第一种样式和功能:(指定页面跳转)

第二种样式和功能:(全选按钮事件和表单内自定义事件)

 

第三种样式和功能:(表单刷新按钮、表单头部排序、可配置显示列的内容)

 

bootstraptable需要引入的文件(以下一律采用cdn方式引入)

<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>bootstrapTable表单</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
        <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">
        <link rel="stylesheet" type="text/css" href="css/bootstrap-table-pagejump.css" />
        <style type="text/css">
         *{
            margin:0;
            padding:0;
         }

        </style>
    </head>
    <body>
     <div class="container">
        <div class="first">
            <h3>第一种样式</h3>
             <table id="mytab" class="table table-hover">
            </table>
        </div>
         <div class="second">
            <h3>第二种样式</h3>
             <table id="AmountTable" class="table table-hover">
            </table>
        </div>
         

     </div>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table-pagejump.js"></script>
    <script type="text/javascript" src="js/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript">
       $('#mytab').bootstrapTable({
              url: 'data.json',
              // method: 'POST',
              queryParams: "queryParams",
              toolbar: "#toolbar",
              sidePagination: "true",
              striped: true, // 是否显示行间隔色
              // search : "true",
              uniqueId: "ID",
              pageSize: "5",
              pagination: true, // 是否分页
              sortable: true, // 是否启用排序
              paginationShowPageGo: true,
              columns: [{
                    field: 'id',
                    title: '序号',
                    width: 120,
                    align: 'center',
                    valign: 'middle'
                  },
                  {
                    field: 'id',
                    title: '历史记录',
                    width: 120,
                    align: 'center',
                    valign: 'middle',
                    formatter: actionFormatter,
                  },
                  {
                      field: 'budget_code',
                      title: '预算编号',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'budget_state',
                      title: '状态',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'budget_type',
                      title: '预算类型',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'proj_code',
                      title: '项目编号',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'proj_name',
                      title: '项目名称',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'customer_operate_pattern',
                      title: '项目操作模式',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'ground_district',
                      title: '落地大区',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'proj_start_date',
                      title: '驱动日期',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'proj_period',
                      title: '项目周期',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  },
                  {
                      field: 'proj_date',
                      title: '最近修改日期',
                      width: 120,
                      align: 'center',
                      valign: 'middle'
                  }
              ],
              onLoadSuccess: function (res) {
                console.log('数据')
              }
        })
     //操作栏的格式化
function actionFormatter(value, row, index) {
      var id = value;
      var result = "";
       result += "<a href='javascript:;' class='btn btn-xs green' onclick=\"EditViewById('" + id + "', view='view')\" title='查看'><button type='button' class='btn btn-default '>查看</button></a>";
      return result;
}
//查看内容
function EditViewById (id) {
    alert(id)
}
    // 预计合同总金额 表单
    $('#AmountTable').bootstrapTable({
          url: 'Amount.json',
          // method: 'POST',
          queryParams: "queryParams",
          toolbar: "#toolbar",
          sidePagination: "true",
          striped: true, // 是否显示行间隔色
          // search : "true",
          uniqueId: "ID",
          pageSize: "5",
          pagination: false, // 是否分页
          sortable: true, // 是否启用排序
          paginationShowPageGo: true,
          columns: [
             {
               checkbox:true
             },
             {
                field: 'id',
                title: '序号',
                width: 120,
                align: 'center',
                valign: 'middle',
              },
              {
                  field: 'material_code',
                  title: '材料代码',
                  width: 120,
                  align: 'center',
                  valign: 'middle'
              },
              {
                  field: 'material_name',
                  title: '材料名称',
                  width: 120,
                  align: 'center',
                  valign: 'middle'
              },
              {
                  field: 'contract_area',
                  title: '合同面积',
                  width: 120,
                  align: 'center',
                  valign: 'middle'
              },
              {
                  field: 'contract_unit_price',
                  title: '合同单价',
                  width: 120,
                  align: 'center',
                  valign: 'middle'
              },
              {
                  field: 'subitem_prop',
                  title: '分项占比',
                  width: 120,
                  align: 'center',
                  valign: 'middle'
              },
              {
                  field: 'contract_subitem_amount',
                  title: '合同分项金额',
                  width: 120,
                  align: 'center',
                  valign: 'middle'
              },
              {
                field: 'price',
                title: '操作',
                width: 120,
                align: 'center',
                valign: 'middle',
                formatter: ActionWrite
              }
          ],
          onLoadSuccess: function (res) {
            console.log('数据')
          },
           onClickRow: function (row, tr,flied) {
            console.log('选中行事件')
           },
          onCheckAll: function (rows) {
            console.log('全部选中事件')
          },
          onUncheckAll: function (rows) {
            console.log('全部不选中事件')
          },
          onUnCheckAll: function (rows) {
            console.log('全部不选中事件')
          },
          onCheck: function (row) {
            console.log('单独选中事件')
          },
          onUncheck:function(row){
            console.log('取消选中')
           
          }
    })
    function ActionWrite (value, row, index) {
      var id = value;
      var result = "";
      result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"GetHeTongId('" + index+ "')\" title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
      result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"GetHeTongId('" + index + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
      return result
    }
    function GetHeTongId (id) {
      alert(id)
    }
    </script>
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>bootstrapTable表单</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
        <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">
        <style type="text/css">
         *{
            margin:0;
            padding:0;
         }
         .fixed-table-toolbar .columns-right button {
            background:#337ab7;
            color:#fff;
         }

        </style>
    </head>
    <body>
      <div class="container">
          <div class="first">
            <h3>第三种样式</h3>
             <table id="tabledemo" data-show-columns="true"></table>
            <div id="toolbar" class="btn-group">
                <input type="hidden" class="form-control" id="selectId" name="selectId">
                <input type="hidden" class="form-control" id="theDataStatus" name="theDataStatus">
                <button id="btn_look" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>查看
                </button>
                <button id="btn_deal" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>处理
                </button>
                <button id="btn_audit" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>审核
                </button>
                <button id="btn_grade" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>评级
                </button>
                <button id="btn_sync" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-sort" aria-hidden="true"></span>传输SAP
                </button>
            </div>
        </div>
      </div>

    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>

    <script type="text/javascript" src="js/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript">
    var columnsArr = [{
            field: 'id',
            title: '序号',
            width: 120,
            sortable: true,
            align: 'center',
            valign: 'middle'
          },
          {
              field: 'budget_code',
              title: '预算编号',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'budget_state',
              title: '状态',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'budget_type',
              title: '预算类型',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'proj_code',
              title: '项目编号',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'proj_name',
              title: '项目名称',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'customer_operate_pattern',
              title: '项目操作模式',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'ground_district',
              title: '落地大区',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'proj_start_date',
              title: '驱动日期',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'proj_period',
              title: '项目周期',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'proj_date',
              title: '最近修改日期',
              width: 120,
              sortable: true,
              align: 'center',
              valign: 'middle'
          }
      ]
       $('#tabledemo').bootstrapTable({
          url: 'data.json',
          // method: 'POST',
          queryParams: "queryParams",
          toolbar: "#toolbar",
          sidePagination: true,
          striped: true, // 是否显示行间隔色
          uniqueId: "ID",
          showRefresh: true, // 是否显示刷新按钮
          pageSize: "5", 
          pagination: true, // 是否分页
          sortable: true, // 是否启用排序
          paginationShowPageGo: true, // 是否跳转页面
          showColumns: true, // 是否全列显示
          columns: columnsArr,
          resizable: true,
          onLoadSuccess: function (res) {
            console.log('数据')
          }
        })

    </script>
    </body>
</html>

其中指定页面跳转的代码,没有cdn 各位可以直接百度搜索下载

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值