Bootstrap Table使用整理(三)
来源:互联网 发布:python 矩阵相乘 编辑:程序博客网 时间:2024/06/06 02:24
一、单元格内容格式化
-
-
-
- $('#table1').bootstrapTable({
- columns: [
- {
- field: 'sno', title: '编号', formatter: function (value, row, index) {
-
- return '<span class="badge">'+(index+1)+'</span>';
- }
- },
- {
- field: 'sno', title: '学生编号', formatter: function (value) {
- return '<a href="#">'+ value + '</a>';
- }
- },
- { field: 'sname', title: '学生姓名' },
- {
- field: 'ssex', title: '性别', formatter: function (value) {
- return '<i class="glyphicon glyphicon-star"></i>' + value;
- }
- },
- { field: 'sbirthday', title: '生日' },
- { field: 'class', title: '课程编号' },
- ],
- url:'@Url.Action("GetStudent","DataOne")'
- });
- <table id="table1"
- data-classes="table table-hover table-condensed"></table>
二、列显示控制,CardView面板显示-
-
-
-
-
-
-
- var $table= $('#table1').bootstrapTable({
- columns: [
- { field: 'sno', title: '学生编号', switchable: false },
- { field: 'sname', title: '学生姓名' },
- { field: 'ssex', title: '性别' },
- { field: 'sbirthday', title: '生日' },
- { field: 'class', title: '课程编号', visible:false },
- ],
- url:'@Url.Action("GetStudent","DataOne")'
- });
- <table id="table1"
- data-classes="table table-hover"
- data-show-columns="true"
- data-height="300"
- data-card-view="true"></table>
三、单选处理 -radio
-
-
-
-
-
-
-
- var $table= $('#table1').bootstrapTable({
- columns: [
- { field: 'sno', title: '学生编号' ,radio:true},
- { field: 'sname', title: '学生姓名' },
- { field: 'ssex', title: '性别' },
- { field: 'sbirthday', title: '生日' },
- { field: 'class', title: '课程编号' },
- ],
- url:'@Url.Action("GetStudent","DataOne")'
- });
- $table.on('click-row.bs.table', function (e, row, $element) {
- $('.success').removeClass('success');
- $($element).addClass('success');
- });
- $('#btn1').click(function () {
-
- var index = $table.find('tr.success').data('index');
-
- var result = $table.bootstrapTable('getData')[index];
- console.info(result);
- alert(result.sname);
- });
- <button class="btn btn-primary" id="btn1">获取表格选中结果</button>
- <table id="table1"
- data-classes="table table-hover"
- data-show-columns="true"
- data-click-to-select="true"
- data-select-item-name="sno"></table>
四、多选处理-checkbox-
-
-
-
-
- var $table= $('#table1').bootstrapTable({
- columns: [
- {
- fileid: 'state', checkbox: true, formatter: function (value, row, index) {
- if (index === 2) {
- return {
- disabled: true,
- checked:true
- }
- }
- if (index === 0) {
- return {
- disabled: true,
- checked: true
- }
- }
- console.info(value);
- return value;
- }
- },
- {
- field: 'sno', title: '学生编号'
- },
- { field: 'sname', title: '学生姓名' },
- { field: 'ssex', title: '性别' },
- { field: 'sbirthday', title: '生日' },
- { field: 'class', title: '课程编号' },
- ],
- url:'@Url.Action("GetStudent","DataOne")'
- });
- $table.on('click-row.bs.table', function (e, row, $element) {
- $('.success').removeClass('success');
- $($element).addClass('success');
- });
- $('#btn1').click(function () {
-
-
- var result = $table.bootstrapTable('getSelections');
- console.info(result);
- var ids = [];
- for (var i = 0; i < result.length; i++) {
- var item = result[i];
- ids.push(item.sno);
- }
- alert(ids);
- });
- <button class="btn btn-primary" id="btn1">获取表格选中结果</button>
- <table id="table1"
- data-classes="table table-hover"
- data-show-columns="true"
- data-click-to-select="true"
- ></table>
五、多选框单选模式
- <button class="btn btn-primary" id="btn1">获取表格选中结果</button>
- <table id="table1"
- data-classes="table table-hover"
- data-show-columns="true"
- data-click-to-select="true"
- data-single-select="true"
- >
- <thead>
- <tr>
- <th data-field="state" data-checkbox="true" data-formatter="checkHandle">选择框</th>
- <th data-field="sno" >编号</th>
- <th data-field="sname">姓名</th>
- <th data-field="ssex">性别</th>
- <th data-field="sbirthday">生日</th>
- <th data-field="class">课程编号</th>
- </tr>
- </thead>
- </table>
-
-
-
-
-
-
- var $table= $('#table1').bootstrapTable({
- url:'@Url.Action("GetStudent","DataOne")'
- });
-
- $table.on('click-row.bs.table', function (e, row, $element) {
- $('.success').removeClass('success');
- $($element).addClass('success');
- });
- $('#btn1').click(function () {
-
-
- var result = $table.bootstrapTable('getSelections');
- console.info(result);
- var ids = [];
- for (var i = 0; i < result.length; i++) {
- var item = result[i];
- ids.push(item.sno);
- }
- alert(ids);
- });
- function checkHandle(value, row, index) {
- if (index === 2) {
- return {
- disabled: true
- };
- }
- if (index === 0) {
- return {
- disabled: true,
- checked: true
- }
- }
- return value;
- }