bootStrap-table之常用事件
1、onClickCell
参数:field, value, row, $element 说明:当单击某一格,就会触发该事件,所需参数如下: - field:此格所在列的字段名 - value:此格的数据 - $element:此行的此列,就是此格(td) 例子: $("#bootstrap-table-id").bootstrapTable({ ... columns:[ {field:name, title:姓名, },{}...], onClickCell:function(field, value, row, $element){ //可以使用field判断点击了哪个colums里面的field。 if(field=="name"){ ... } //使用row可以获得上面存有字段的值: var myname=row.name } })
2、onLoadSuccess
参数:data 说明:当所有数据被加载时触发 例子: $("#bootstrap-table-id").bootstrapTable({ ... columns:[ {field:name, title:姓名, },{}...], onLoadSuccess:function(data){ //data为当前页面加载所有数据的详细信息 //如果分了5页,当前是第2页,则data是包含第二页所有数据。 console.info(data) } })
3、formatter
属性:data-formatter 类型:Function 默认值:undefined 作用描述: 需要此列的对象。 某格的数据转换函数,需要三个参数: -value: field(字段名) -row:行的数据 -index:行的(索引)index 注意:当value为undifined的时候,调用一些方法比如value.length会报错。 例子: $("#bootstrap-table-id").bootstrapTable({ ... columns:[ { field:id, title:序号, formatter:function(value,row,index){ //序号从1开始 return index+1; } }, {field:, title:操作, events:operateEvents, formatter:playButtonFunction },{}...], ... }) playButtonFunction(value,row,index){ return[ <a id="tableid" href="#aa" data-toggle=""><img src="img/bb.png" alt="" id="imgid"></a> ].join("") } window.operateEvents={ //触发点击事件 "click #tableid":function(e,value,row,index){ console.info(row) //可以使用row获取本行各种属性值。 } }