我正在使用 dataTables插件
在我的可排序列上,我想用一个按钮替换列文本。
但是这样做:
$( oSettings.aoColumns[i].nTh).text();
我可以检索相应列的文本,但是
$( oSettings.aoColumns[i].nTh).text("some text");
$( oSettings.aoColumns[i].nTh).html("<a href='#'>some button</a>");
什么都不做。
有人能告诉我为什么我可以从单元格中检索信息但不能编辑它的内容吗?不一定是数据表问题,但也许有人遇到过类似的问题。
感谢您的帮助!
编辑:这是解决方案:
在你的表调用中指定,哪些列应该是可排序的 = 这些得到一个 .jqmSorter 类
"aoColumns": [
/* Select */ {"bSortable": false },
/* Type */ {"sClass": "jqmSorter"},
/* From */ {"bSortable": false },
/* Status */ {"bSortable": false },
],
然后调用 fnHeaderCallback,我在其中用 JQM 按钮替换标题单元格内容:
"fnHeaderCallback": function( nHead ) {
$(nHead).closest('thead').find('.jqmSorter').each( function () {
var sortTitle = $(this).text(),
sortButton =
$( document.createElement( "a" ) ).buttonMarkup({
shadow: false,
corners: false,
theme: 'a',
iconpos: "right",
icon: "ui-icon-radio-off"
})
sortButton.find('.ui-btn-text').text(sortTitle);
$(this).html( sortButton )
sortButton.addClass("colHighTrigger");
});
}
最佳答案
你可以这样做:
在定义 table columns
时(如果您还没有这样做,请定义),并使用表列定义(在 JSON 中)的 sClass
属性。
在此之后,该类将应用于表列。
在此之后,使用数据表的回调
函数:fnRowCallback
在此,将 html 设置为
$(nRow, '.your_class').html('Your HTML Values');
这将在呈现表格的每一行时调用。
如果您不希望它在每一行都执行,您可以使用 if 条件来控制它。
关于javascript - 如何更改数据表中标题单元格的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9412443/