當試圖突出顯示第一頁頁面之外的行時,Datatables插件給了我一些問題。當表格單元格匹配時,數據表突出顯示超出第一頁頁面的行
正如您將在下面的示例JSFiddle中看到的,我正在對負載上的位置列進行排序。當一行中有兩個或多個相關位置時,我們突出顯示父錶行。我遇到的問題是,如果在最後一個錶行中的第一頁上有一個位置,並且與第一個位置上的第一個位置匹配第一頁上的最後一個表格行的第二頁未突出顯示。我在這裏使用的例子是開發人員的職位。
的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", "");
}
});
}
});