我目前用的版本是 bootstrap-table 1.18.3
背景: 动态列 ,表格字段值颜色 根据值的大小而变化,后台设定好列返回给前端json。
问题: bootstrap-table 修改字段值颜色需要用到formatter参数,但由于返回json的缘故,前端会认为这个是字符串。
解决:
修改源码:
“this.header.formatters[column.fieldIndex] = column.formatter ” 部分
为: this.header.formatters[column.fieldIndex] = (typeof column.formatter == “string” ? eval(column.formatter) : column.formatter )
就可以了。
参考: https://github.com/wenzhixin/bootstrap-table/blob/1.18.3/src/bootstrap-table.js
具体的表格值改变颜色-场景红涨绿跌: https://examples.bootstrap-table.com/index.html?bootstrap3#column-options/formatter.html
本文介绍如何在使用bootstrap-table 1.18.3版本时,通过修改源码实现表格字段值的颜色根据值的变化而变化。针对动态列的需求,解决因返回JSON导致前端无法直接应用颜色格式化的问题。
4万+

被折叠的 条评论
为什么被折叠?



