Datatable Javascript链接在第2页不起作用

Datatable Javascript Link not working on 2nd page

本文关键字:2页 不起作用 Javascript 链接 Datatable      更新时间:2023-09-26

我在一个表中有一个数据列表,并且正在使用dataTable插件进行分页。

然而,我的最后一个专栏是一个链接。当我转到第二页时,我无法单击该链接,但该链接仅在表格的第一页打开。

当我没有数据表时,所有链接的工作,但当我添加它时,它不起作用。。。

我的代码:

 <table id="PartsResultListGrid" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.PartsRequestOrderNum)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Call_Num)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.DetailView)
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.PartsRequestOrderNum)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Call_Num)
                </td>
                <td>
                    <div data-callno='@item.PartsRequestOrderNum' data-url="@Url.Action("GetPartsInfo", "Parts")">
                        <div class="PartsViewSubmit toolbarIcon">
                            <div class="toolbarIconText">View</div>
                        </div>
                    </div>
                </td>
            </tr>
        }
    </tbody>
</table>

Javascript:

<script type="text/javascript">
$(document).ready(function () {
    $('#PartsResultListGrid').dataTable({
        "bSort": false,
    });
});
</script>

知道为什么会发生这种事吗?

我在里面的ajax链接打开了链接:

        $('.PartsViewSubmit').click(function () {
        $.ajax({
            type: "GET",
            url: $(this).parent().data("url"),
            data: { PartsRequestOrderNum: $(this).parent().data("callno") },
            success: function (data) {
                $("#PartsDetail").html(data);
            },
        });
    });

您需要使用委派事件:

委派事件的优势在于,它们可以从以后添加到文档中的子元素。通过选择保证在已附加委托事件处理程序,可以使用委托事件避免了频繁附加和删除事件处理程序的需要。

所以在你的情况下,我会这样做:

$(document.body).on('click', '.PartsViewSubmit', function() {
    $.ajax({
        ...
    });
});