How can I get 'offset' value in Jquery Datatables plugin
I want to print seri开发者_高级运维al-no on each page. This serial-no should always be in ascending order, regardless of sorting of any column. Lets suppose I am on page # 3 and 'limit' is set to 10.
Then serial-no column should print 21, 22, 23, ..., 30.
How can I get this in jQuery datatables plugin.
Thanks in advance
There's an fnRowCallback
that should let you do what you want:
This function allows you to 'post process' each row after it have been generated for each table draw, but before it is rendered on screen.
And the callback's fourth parameter is
The index of the data in the full list of rows (after filtering)
So you should be able to use the fourth parameter to the callback to add the row number to the row (which is the callback's first parameter).
you actually no need to worry about anything , just make it simply
create s.no from server side just like bellow json ... then you no need to worry about anything like offset
JSON
{
"sEcho": 0,
"iTotalRecords": 12,
"iTotalDisplayRecords": 12,
"aaData": [
["1","item1"],["2","item1"],["3","item1"],["4","item1"],["5","item1"],["61","item1"],["7","item1"],["8","item1"],["9","item1"],["10","item1"],["11","item1"],["12","item1"]
]
}
SCRIPT
<script type="text/javascript">
$(document).ready(function() {
var oTable = $('#category_table').dataTable( {
"aoColumns": [
{ "sClass": "number", "bSortable": false },
{ "sClass": "nonedit", "bSortable": false }
],
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "serverpage.php",
"fnDrawCallback": function () {
}
});
});
</script>
MARKUP
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="category_table">
<thead>
<tr>
<th width="3%" style="text-align:center;">S.No</th>
<th>item Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5" class="dataTables_empty">Loading data from server</td>
</tr>
</tbody>
<tfoot>
<tr>
<th width="3%" style="text-align:center;">#</th>
<th>item Name</th>
</tr>
</tfoot>
</table>
精彩评论