如何在不重新加载页面的情况下刷新数据表(jquery 插件)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5870947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:55:56  来源:igfitidea点击:

how to refreshing datatables (jquery plug in) without reload page

jqueryajaxdatatable

提问by bungdito

please help me, i'm very newbie i have question about datatables (jquery plug in).

请帮助我,我是新手,我对数据表(jquery 插件)有疑问。

at every rows data in datatables grid, I have button to delete data. when i click delete button, data at that row deleted.

在数据表网格中的每一行数据中,我都有删除数据的按钮。当我点击删除按钮时,该行的数据被删除。

the question is, can I refresh data table without reloading the page ? so the rows can be decrease when i click delete button without reloading the page.

问题是,我可以在不重新加载页面的情况下刷新数据表吗?所以当我点击删除按钮而不重新加载页面时,行可以减少。

this is my code: (just FYI my table id for datatble is: id="mydatatable")

这是我的代码:(仅供参考,我的数据表的表 ID 是:id="mydatatable")

html delete button on each rows data:
-------------------------------------

<button onclick="delete('id')">Delete</button>


javascript:
-----------

delete(id)
{
    delete_ajax(id);            //deleting data using ajax

    window.location.reload()    //reloading page, this what i want to change 
                                //(just refresh datatable grid without reload the page)
}

many thanks :)

非常感谢 :)

采纳答案by digitaljoel

Have a look at the api. You should be able to call fnDeleteRow on your datatables object.

看看api。您应该能够在数据表对象上调用 fnDeleteRow。

http://www.datatables.net/api

http://www.datatables.net/api

回答by Adam F

This is one of many ways to quickly refresh a table

这是快速刷新表的众多方法之一

table=$("table.datatable").dataTable();
table.fnPageChange("first",1);

回答by Royal.O

We can use DataTable API.

我们可以使用 DataTable API。

var currentPage = ListTable.page();

ListTable.page(0).draw( 'page' );

回答by shanmugavel

This will do the trick ->

这将解决问题->

oTable.fnDraw(false);

oTable.fnDraw(false);

U can call like this

你可以这样打电话

     setInterval(function ref(){
    oTable.fnDraw(false);
    },8000);

回答by Jatin Dhoot

if your delete_ajax()function is handling the business logic and if you want to remove the current row you can easily remove the row using $('rowobject').hide().

如果您的delete_ajax()函数正在处理业务逻辑,并且您想删除当前行,则可以使用以下命令轻松删除该行$('rowobject').hide().

回答by Crazy Crab

If you only want to reload the current page data, you can use this code.

如果您只想重新加载当前页面数据,则可以使用此代码。

table.ajax.reload();

Please refer to this DataTable ajax.reload()

请参考这个DataTable ajax.reload()