【发布时间】:2017-12-01 11:14:52
【问题描述】:
我正在使用 jQuery 的数据表插件,但是我遇到了渲染函数的问题:
我有一个在列中包含一些 html 元素的字符串,我不希望 html 元素在表格中呈现,所以我使用函数 $.fn.dataTable.render.text()
我也只想将此数据作为预览,因为字符串可能非常长,因此我使用省略号函数$.fn.dataTable.render.ellipsis(40)
省略号函数定义为here:
// https://datatables.net/manual/data/renderers#Text-helper
$.fn.dataTable.render.ellipsis = function (cutoff) {
return function (data, type, row) {
if (type === 'display') {
var str = data.toString(); // cast numbers
return str.length < cutoff ?
str :
str.substr(0, cutoff - 1) + '…';
}
// Search, order and type can use the original data
return data;
};
};
是否有可能以任何方式组合这些功能?
最接近我的问题的解决方案是在数据表论坛上找到的this。
这正是我想要做的,但它不起作用,因为d = renderArray[r](d, type, row, meta); 不是一个函数。
提前致谢。
【问题讨论】:
-
查看
console.table( $.fn.dataTable.render )它将输出您可用的渲染器表,我敢打赌您会错过您尝试使用的渲染器之一。包括您缺少的内容,我相信它会起作用。 -
@davidkonrad 谢谢!两种渲染都成功地单独工作,但是我遇到的问题是我不能将两者都应用于单个列。
-
您只需使用
$.fn.dataTable.render.multi,正如您所提到的,我在 01.12 中试用了它(可以轻松制作一个新的),这是一个绝妙的解决方案。但它只有在您拥有所有渲染器时才有效。 -
@davidkonrad 是否可以向我展示那个小提琴,因为我自己似乎无法解决它,我还用表格的截图更新了这个问题。表中缺少名称这一事实会影响它们的工作方式吗?
-
我没有保存链接,这是一个新的 jsfiddle.net/0f9Ljfjr/1006 使用省略号和矩,DT 版本 1.10.1
标签: javascript jquery datatable datatables