删除和恢复数据表分页点击功能

Remove and Restore datatables pagination click functionality

本文关键字:功能 分页 数据表 恢复 删除      更新时间:2023-09-26

我在一个网页上有一个数据表实例,该实例具有全数字分页。这包括第一个、上一个、下一个和最后一个按钮以及单独编号的按钮。

表中的每一行都有一个"编辑"链接。当我点击它时,我想禁用分页。当我单击"取消"按钮时,我想恢复分页功能。我可以很容易地完成第一部分,但我无法恢复分页单击功能。这是我的代码:

function ghostPage(state)
{
    // In this method, 'state' will be either true or false
    // If it's true, remove the click handler
    // If it's false, restore the click handler
    if(state)
    {
        $('#displayTable_paginate').find('a').each(function(e){
            $(this).off('click');
        })
    }
    else
    {
        $('#displayTable_paginate').find('a').each(function(){
            $(this).on('click');
        })
    }
}

如果您想保存点击处理程序并稍后恢复,请尝试此操作。

function saveClickHander(){
    var $this;
    $('#displayTable_paginate').find('a').each(function(e){
        $this = $(this);
        $this.data().originalClick = $this.data("events")['click'][0].handler;
    }) 
}
function ghostPage(state)
{
    // In this method, 'state' will be either true or false
    // If it's true, remove the click handler
    // If it's false, restore the click handler
    if(state)
    {
        $('#displayTable_paginate').find('a').each(function(e){
            $(this).off('click');
        })
    }
    else
    {
        var $this;
        $('#displayTable_paginate').find('a').each(function(){
            $this = $(this);
            $this.on('click', $this.data().originalClick);
        })
    }
}