【发布时间】:2015-07-13 04:43:41
【问题描述】:
当我试图突出显示第一个分页之外的行时,Datatables 插件给了我一些问题。
正如您将在下面的示例 JSFiddle 中看到的,我在加载时对位置列进行排序。当一行中有 2 个或更多相关位置时,我们会突出显示父表行。我遇到的问题是,如果第一页上有一个位置在最后一个表行中并且与第一个位置相匹配第二页 第一页的最后一个表格行未突出显示。我在这里使用的示例是开发人员职位。
JSFiddle
https://jsfiddle.net/ebRXw/563/
JS
$(document).ready(function () {
$('table').dataTable({
"paging": true,
"ordering": true,
"filter": false,
"length": false,
"info": false,
"order": [
[1, "asc"]
]
});
highlight();
$('table').on('draw.dt', function () {
if ($("thead th:nth-child(2)").hasClass("sorting_desc") || $("thead th:nth-child(2)").hasClass("sorting_asc")) {
highlight();
} else {
$("td").removeClass("info");
$("td").css("border-bottom", "");
}
});
function highlight() {
var duplicate = false;
$("table tbody tr").each(function () {
var $current = $(this).children(":nth-child(2)");
var $next = $(this).next().children(":nth-child(2)");
if ($current.text() === $next.text() && !duplicate) {
duplicate = true;
$current.parent().children().addClass("info");
$current.parent().prev().children().css("border-bottom", "1px solid #333");
} else if ($current.text() === $next.text() && duplicate) {
$current.parent().children().addClass("info");
} else if ($current.text() !== $next.text() && duplicate) {
$current.parent().children().addClass("info");
$current.parent().children().css("border-bottom", "1px solid #333");
duplicate = false;
} else {
$current.parent().children().removeClass("info");
$current.parent().children().css("border-bottom", "");
}
});
}
});
【问题讨论】:
标签: javascript jquery datatables