Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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")

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

like image 501
bungdito Avatar asked May 03 '11 14:05

bungdito


People also ask

How do I refresh a table without refreshing the whole page?

You will need to use a client-side scripting language such as javascript in order to be able to refresh certain contents on your HTML page. A very common library that is used is jQuery.

What is a DataTables warning?

DataTables warns about the use of them by default, as the majority of the time they are not intended for display - for example, rather than showing null in the table, you might want to show Not yet set, or simply an empty string (empty cell). For this, DataTables has a columns. defaultContent option.


1 Answers

This is one of many ways to quickly refresh a table

const table=$("table.datatable").dataTable();
table.fnPageChange("first",1);
like image 163
Adam F Avatar answered Sep 24 '22 05:09

Adam F