数据表Javascript链接无法在第二页上运行 [英] Datatable Javascript Link not working on 2nd page

查看:96
本文介绍了数据表Javascript链接无法在第二页上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a list of data in a table and am using the dataTable plugin for pagination.

但是,我的最后一列是一个链接。当我转到第二页时,我无法点击链接,但链接仅在表格的第一页打开。

However, my last column is a link. When I go to the 2nd page I cannot click the link, but the link opens only on the first page of the table.

当我没有数据表时链接的工作,但它是当我添加它它没有工作...

When I did not have the datatable all the linked work, but it was when i added this it didnt work...

我的代码:

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

Javascript:

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

知道为什么会这样吗?

我在其中的ajax链接打开链接:

My ajax link inside this which opens the link:

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


推荐答案

你需要使用 委派活动

You need to use a delegated event :


委托事件的优势在于它们可以处理来自
后代元素的事件,这些元素稍后会添加到文档中。通过
选择在附加
委托事件处理程序时保证存在的元素,您可以使用委托事件到
,避免频繁附加和删除事件处理程序。

Delegated events have the advantage that they can process events from descendant elements that are added to the document at a later time. By picking an element that is guaranteed to be present at the time the delegated event handler is attached, you can use delegated events to avoid the need to frequently attach and remove event handlers.

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

So in your case, I would do this instead :

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

这篇关于数据表Javascript链接无法在第二页上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆