同事最近有一个需要,要求bootstrap-table的指定某行某列的某一个启用编辑,额~没办法是否bootstrap构造器中改了,代码如下,成功骗得同事的关注,哈哈哈
//获取bootstrap构造器
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initTable = BootstrapTable.prototype.initTable;
BootstrapTable.prototype.initTable = function () {
var that = this;
_initTable.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.editable) {
return;
}
$.each(this.columns, function (i, column) {
if (!column.editable) {
return;
}
column.formatter = function (value, row, index) {
//满足一定条件直接返回value
if (index == 0 || index == 6)
{
return value;
}
return ['<a href="javascript:void(0)"',
' data-name="' + column.field + '"',
' data-pk="' + row[that.options.idField] + '"',
' data-value="' + value + '"',
'>' + '</a>'
].join('');
};
});
};
效果如下: