jQuery的数据表无法从第二页 [英] jquery data table not working from second page

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

问题描述

我正在使用jquery数据表1.9.4和jquery 1.9.1,并且我试图在单击事件上执行这样的ajax调用.

I am using jquery Data table 1.9.4 and jquery 1.9.1 and i am trying to perform ajax call like this on click event.

$(".icon-trash").on('click',function () {
                // alert($(this).attr('id'));
                $.post('/WorkOrderRequest/DeleteWOR',
                        { id: $(this).attr('id') },

                        function (returndata) 
                        {

                            if (returndata.ok) 
                            {
                                window.alert(' deleted!');
                                $("#emp" + idemployee).hide('slow');
                            }
                            else {
                                window.alert(' error : ' + returndata.message);
                            }

                    });

            });

html部分:

@foreach (var item in Model)
                    {

                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.ProjectCode)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.WO_Date)
                            </td>


                            <td>
                             <a  id='@(item.WO_ID)' class="icon-edit" />
                               |                               
                             <a  id='@(item.WO_ID)' class="icon-trash" />
                           </td>
                        </tr>
                    }

它在第一页上工作正常,但是从第二页上没有显示任何结果.请帮助

It is working fine on first page but from second page its not showing any result. Please help

推荐答案

分页的工作方式是将当前页面不需要的行从DOM中删除.因此,删除html时,您直接绑定到这些元素的所有事件处理程序都会丢失.

The way pagination works, rows not needed by current page are removed from the DOM. Therefore any event handlers you bind directly to those elements are lost when the html is removed.

您需要使用on()的委派语法将处理程序绑定到永久页面中的资产.这可以是父表或树上的任何其他父表,包括document

You need to use delegation syntax of on() to bind the handler to an asset in page that is permanent. This could be the parent table or any other parent up the tree, including document

$('#TableID').on('click','.icon-trash',function () {...

API参考: http://api.jquery.com/on/

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

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