Bootstrap Table使用整理(四)-工具栏

来源:互联网 发布:java.io.temp 编辑:程序博客网 时间:2024/06/05 16:29

一、启用默认支持的工具栏

[javascript] view plain copy
 print?
  1. /* 
  2. * data-search 是否显示搜索框 
  3. * data-show-refresh 是否像是刷新按钮,注:刷新操作会重新请求数据,并带着请求参数 
  4. * data-show-toggle 是否显示面板切换按钮 
  5. * data-show-columns 是否显示列控制按钮 
  6. */  
  7. $('#table1').bootstrapTable({  
  8.     columns: [  
  9.         { field: 'sno', title: '学生编号' },  
  10.         { field: 'sname', title: '学生姓名' },  
  11.         { field: 'ssex', title: '性别' },  
  12.         { field: 'sbirthday', title: '生日' },  
  13.         { field: 'class', title: '课程编号' },  
  14.     ],  
  15.     url:'@Url.Action("GetStudent","DataOne")'  
  16. });  
[html] view plain copy
 print?
  1. <table id="table1"  
  2.        data-classes="table table-hover "  
  3.        data-search="true"  
  4.        data-show-refresh="true"  
  5.        data-show-toggle="true"  
  6.        data-show-columns="true"></table>  



二、扩展工具栏使用

[javascript] view plain copy
 print?
  1. /* 
  2. * data-toolbar 用于指定id的div扩展工具栏,这种方式类似EaseUI中的datagird 
  3. * queryParams 请求服务器数据时,你可以通过重写参数的方式添加一些额外的参数,例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含 
  4.                 limit, offset, search, sort, order 否则, 需要包含: 
  5.                 pageSize, pageNumber, searchText, sortName, sortOrder. 
  6.                 返回false将会终止请求 
  7. */  
  8. var $table1= $('#table1').bootstrapTable({  
  9.     columns: [  
  10.         { field: 'sno', title: '学生编号' },  
  11.         { field: 'sname', title: '学生姓名' },  
  12.         { field: 'ssex', title: '性别' },  
  13.         { field: 'sbirthday', title: '生日' },  
  14.         { field: 'class', title: '课程编号' },  
  15.     ],  
  16.     url: '@Url.Action("GetStudent","DataOne")',  
  17.     queryParams: function (params) {  
  18.         params.name = '张三丰';  
  19.         //特别说明,返回的参数的值为空,则当前参数不会发送到服务器端  
  20.         params.sex = $('input[name="sex"]:checked').val();  
  21.         return params;  
  22.     }  
  23. });  
  24. //刷新方法  
  25. $('#heartBtn').click(function () {  
  26.     ////刷新处理,指定query 的参数,注:此地方指定的参数,仅在当次刷新时使用  
  27.     //$table1.bootstrapTable('refresh', {  
  28.     //    query: {  
  29.     //        name: '张三'  
  30.     //    }  
  31.     //});  
  32.     $table1.bootstrapTable('refresh');  
  33. });  
[html] view plain copy
 print?
  1. <table id="table1"  
  2.        data-classes="table table-hover "  
  3.        data-search="true"  
  4.        data-show-refresh="true"  
  5.        data-show-toggle="true"  
  6.        data-show-columns="true"  
  7.        data-toolbar="#toolbar"></table>  
  8. <div id="toolbar">  
  9.     <div class="btn-group">  
  10.         <button class="btn btn-default">  
  11.             <i class="glyphicon glyphicon-plus"></i>  
  12.         </button>  
  13.         <button class="btn btn-default">  
  14.             <i class="glyphicon glyphicon-heart" id="heartBtn"></i>  
  15.         </button>  
  16.         <button class="btn btn-default">  
  17.             <i class="glyphicon glyphicon-trash"></i>  
  18.         </button>  
  19.     </div>  
  20.     <div class="form-group">  
  21.         <label class="control-label">性别:</label>  
  22.         <label class="radio-inline">  
  23.             <input type="radio" name="sex" value="男" /> 男  
  24.         </label>  
  25.         <label class="radio-inline">  
  26.             <input type="radio" name="sex" value="女" /> 女  
  27.         </label>  
  28.     </div>  
  29. </div>