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

来源:互联网 发布:办公软件的基础知识 编辑:程序博客网 时间:2024/06/05 17:36
$('#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"); 
           }
        };
原创粉丝点击