我怎样才能获得“抵消”? Jquery Datatables 插件中的值

发布于 2024-10-31 12:04:55 字数 198 浏览 0 评论 0原文

我想在每一页上打印序列号。无论任何列的排序如何,此序列号应始终按升序排列。假设我在第 3 页,“限制”设置为 10。

然后序列号列应打印 21, 22, 23, ..., 30。

我如何在 jQuery 数据表插件。

提前致谢

I want to print serial-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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离鸿 2024-11-07 12:04:55

有一个 fnRowCallback 应该可以让你做你想做的事情:

此函数允许您在为每个表格绘制生成每一行之后、在屏幕上呈现每一行之前对其进行“后处理”。

回调的第四个参数是

完整行列表中数据的索引(过滤后)

因此您应该能够使用回调的第四个参数将行号添加到该行(这是回调的第一个参数)。

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).

末骤雨初歇 2024-11-07 12:04:55

你实际上不需要担心任何事情,只需让它简单地

从服务器端创建 s.no 就像下面的 json 一样......然后你不需要担心像 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 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>

标记

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文