【发布时间】:2012-03-13 19:44:27
【问题描述】:
我正在使用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");
});
}
【问题讨论】:
-
你想在渲染数据表时这样做还是想在渲染自身时这样做?
-
它应该只发生一次,当数据表被渲染时。该按钮仅用于视觉外观(Jquery Mobile 仅图标按钮,我根据排序顺序切换图标类)
标签: javascript jquery html datatables innerhtml