我有一个包含数百个项目的数据表,其中有一个固定的 50 iDisplayLength 选项。我需要能够在加载的节点中找到特定行所在的页面。
我所做的只是获取位置,不幸的是,内部行位置与当前排序和过滤的行索引不对应。
作为jsFiddle上的示例。我可以检索位置或行#tr4(位置 3),但我需要的 iDisplayStart 是 2。
<table id="example">
<thead>
<tr>
<th>ID</th>
<th>Rendering engine</th>
<th>Browser</th>
<th>Platform(s)</th>
<th>Engine version</th>
<th>CSS grade</th>
</tr>
</thead>
<tbody>
<tr id="tr1" class="odd gradeX">
<td>1</td>
<td>Trident</td>
<td>Internet Explorer 4.0</td>
<td>Win 95+</td>
<td class="center"> 4</td>
<td class="center">X</td>
</tr>
<tr id="tr2" class="even gradeC">
<td>2</td>
<td>Trident</td>
<td>Internet Explorer 5.0</td>
<td>Win 95+</td>
<td class="center">5</td>
<td class="center">C</td>
</tr>
<tr id="tr3" class="odd gradeA">
<td>3</td>
<td>Trident</td>
<td>Internet Explorer 5.5</td>
<td>Win 95+</td>
<td class="center">5.5</td>
<td class="center">A</td>
</tr>
<tr id="tr4" class="even gradeA">
<td>4</td>
<td>Trident</td>
<td>Internet Explorer 6</td>
<td>Win 98+</td>
<td class="center">6</td>
<td class="center">A</td>
</tr>
<tr id="tr5" class="odd gradeA">
<td>5</td>
<td>Trident</td>
<td>Internet Explorer 7</td>
<td>Win XP SP2+</td>
<td class="center">7</td>
<td class="center">A</td>
</tr>
</tbody>
</table>
var oTable = $("#example").dataTable({
"sDom": '<"clear">rtip<"clear">',
"bPaginate": true,
"iDisplayLength": 2,
});
var row = $(oTable.fnGetNodes()).filter("#tr4");
console.log(row[0]);
var position = oTable.fnGetPosition(row[0]);
console.log(position);
console.log(oTable.fnSettings()._iDisplayStart);;
// position is 3 but the page displayStart I need is 2.