简体   繁体   English

Bootstrap 4 数据表 - 使用 js 获取分页事件

[英]Bootstrap 4 Data table - Get Pagination event with js

I have the following table on my cshtml :我的cshtml上有下表:

<table class="table table-striped table-bordered table-hover dataTables-example" id="example">
    <thead>
        <tr align="left">
            <th>
                //header
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
        <tr>
            <td>
                //Body
            </td>

        </tr>
        }
    </tbody>
</table>

It creates the pagination itself.它创建了分页本身。 inspecting the code I can see that the pagination element is the following:检查代码我可以看到分页元素如下:

<div class="dataTables_paginate paging_simple_numbers" id="example_paginate"><ul class="pagination">

The problem here is that I need to capture the click on the pagination to send the page number to the server, I've already tried to add an onClick to that id selfgenerated on the view but it's not working.这里的问题是我需要捕获对分页的点击以将页码发送到服务器,我已经尝试将onClick添加到视图上自行生成的 id 中,但它不起作用。

Any ideas on this?对此有什么想法吗?

Maybe you can try to add id to href of anchor tag,here is a demo:也许您可以尝试将 id 添加到锚标签的 href,这是一个演示:

<ul class="pagination">
  <li class="page-item"><a class="page-link" href="?pageNum=1">1</a></li>
  <li class="page-item"><a class="page-link" href="?pageNum=2">2</a></li>
  <li class="page-item"><a class="page-link" href="?pageNum=3">3</a></li>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM