Table.api.formatter.toggle默认是用id作为主键,如果这个数据表的主键不是id,绑定的数据会变为undefined,从而导致执行失败(未更新任何行)。
打开对应JS文件 修改如下
formatter: function (value, row, index) {
var table = this.table;
var options = table ? table.bootstrapTable('getOptions') : {};
var pk = options.pk || "cid";
var color = typeof this.color !== 'undefined' ? this.color : 'success';
var yes = typeof this.yes !== 'undefined' ? this.yes : 1;
var no = typeof this.no !== 'undefined' ? this.no : 0;
var url = typeof this.url !== 'undefined' ? this.url : '';
var disable = false;
if (typeof this.disable !== "undefined") {
disable = typeof this.disable === "function" ? this.disable.call(this, value, row, index) : this.disable;
}
return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change " +
(disable ? 'btn disabled' : '') + "' data-id='" + row[pk] + "' " + (url ? "data-url='" + url + "'" : "") +
" data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on " +
(value == yes ? 'text-' + color : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
}