微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

bootstrap-table如何给行内添加操作函数及功能按键

$('#table').bootstrapTable('destroy'); 
$('#table').bootstrapTable({
// data:reet.data,
url:'../data/yonghuguanli.json',
// uniqueId: "SOBID",
striped:true,
pagination:true,
clickToSelect:true,
height:580,
   columns: [{
    checkBox:true, 
   },{
       field: 'id',       
      sortable:true,
       title: '组织编码',
       sortable: true,
   },{
       field: 'name',
       title: '组织名称',
       sortable: true,
   },{
       field: 'lexing',
       title: '账套编号',
       sortable: true
   },{
       field: 'zt',
       title: '账套名称',
       sortable: true
   }, {
       field: 'operate',
       title: '操作',
       align: 'center',
       events: "operateEvents",
       formatter: operateFormatter
        }],

});

 

 

2:表格中增加按钮

operateFormatter(value, row, index):这三个参数是bootsharp-table认的

 

 

function operateFormatter(value, row, index) {
            return [
                '<button type="button" class="RoleOfA btn btn-default  btn-sm" style="margin-right:15px;">A权限</button>',
                '<button type="button" class="RoleOfB btn btn-default  btn-sm" style="margin-right:15px;">B权限</button>',
                '<button type="button" class="RoleOfC btn btn-default  btn-sm" style="margin-right:15px;">C权限</button>',
                '<button type="button" class="RoleOfD btn btn-default  btn-sm" style="margin-right:15px;">绑定D</button>',
                '<button type="button" class="RoleOfEdit btn btn-default  btn-sm" style="margin-right:15px;">编辑</button>'
            ].join('');

        }

 

 

3:注册按钮的点击事件

每个按钮对应哪个点击事件,是用Class里面的属性标识的,如上步骤2(比如:RoleOfA)

 

 

window.operateEvents = {
            'click .RoleOfA': function (e, value, row, index) {
                alert("A");            
         },
            'click .RoleOfB': function (e, value, row, index) {
                alert("B");            
         },
          'click .RoleOfC': function (e, value, row, index) {
                alert("C");            
         },
        'click .RoleOfEdit': function (e, value, row, index) {
        alert("D"); 
           }
        };

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

相关推荐