不,这不可能出现在文本之后,因为箭头实际上是动态附加到<th> 的 CSS 类中的背景图像。但是你可以从最右向左改变位置:
table.dataTable thead .sorting_asc {
background: url("http://cdn.datatables.net/1.10.0/images/sort_asc.png") no-repeat center left;
}
table.dataTable thead .sorting_desc {
background: url("http://cdn.datatables.net/1.10.0/images/sort_desc.png") no-repeat center left;
}
table.dataTable thead .sorting {
background: url("http://cdn.datatables.net/1.10.0/images/sort_both.png") no-repeat center left;
}
演示 -> http://jsfiddle.net/ttcz5odt/
更新 - 如何在文本之后直接放置箭头图标。
给它一些额外的想法 - 稍微“破解”它确实是可能的。诀窍是禁用<th> 背景并使用原始数据表背景不断注入/删除<span>。
CSS(除了禁用原始):
span.arrow-hack {
margin-left: 5px;
}
span.asc {
background: url("http://cdn.datatables.net/1.10.0/images/sort_asc.png") no-repeat center right;
}
span.desc {
background: url("http://cdn.datatables.net/1.10.0/images/sort_desc.png") no-repeat center right;
}
span.sort {
background: url("http://cdn.datatables.net/1.10.0/images/sort_both.png") no-repeat center right;
}
脚本:
var spanSorting = '<span class="arrow-hack sort"> </span>',
spanAsc = '<span class="arrow-hack asc"> </span>',
spanDesc = '<span class="arrow-hack desc"> </span>';
$("#example").on('click', 'th', function() {
$("#example thead th").each(function(i, th) {
$(th).find('.arrow-hack').remove();
var html = $(th).html(),
cls = $(th).attr('class');
switch (cls) {
case 'sorting_asc' :
$(th).html(html+spanAsc); break;
case 'sorting_desc' :
$(th).html(html+spanDesc); break;
default :
$(th).html(html+spanSorting); break;
}
});
});
更新箭头图标:
$("#example th").first().click().click();
现在看起来就像我们想要的一样! :
演示 -> http://jsfiddle.net/dmn4q141/