5

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

6 Answers 6

5

This is one of many ways to quickly refresh a table

const table=$("table.datatable").dataTable();
table.fnPageChange("first",1);
Sign up to request clarification or add additional context in comments.

Comments

2

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

http://www.datatables.net/api

2 Comments

actually i'm not just need for delete only, but also for add and edit. so maybe i need for refreshing the datatables :)
Click through to the linked documentation. There's fnAddData and fnUpdate which will likely fit your need.
1

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().

1 Comment

Here i am assuming you are using jQuery for javascript processing as you have used jquery in tags. $('rowobject') is current row's object
1

This will do the trick ->

oTable.fnDraw(false);

U can call like this

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

Comments

0

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

Comments

0

We can use DataTable API.

var currentPage = ListTable.page();

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.