Refresh table / DataTables 1.10.0

Refresh table / DataTables 1.10.0

andrew1986andrew1986 Posts: 12Questions: 5Answers: 0

Guys,

I'm using the version 1.10, on the previous version I was able to make refresh without any problems, right now I can't, I would appreacite if someone can put me on the right direction, I have a table which looks like this:

var my_table = $('#table').DataTable({
data: data,
columns: [
{ data: 'user', className: "user" },
{ data: 'pw', className: "password" },
{ data: 'other Info', className: "other" }
]
});

This render my table perfectly, however, If I add a new user I need to refresh the table however I'm not able to, and I cannot find the parameters to create a refresh_Table function.

Any advises?

Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    my_table.draw();

  • andrew1986andrew1986 Posts: 12Questions: 5Answers: 0

    I've already try it, however It doesnt work.

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    You will have to show more of your code..

    When you say add a new user????? To where? how?

  • andrew1986andrew1986 Posts: 12Questions: 5Answers: 0

    Basically I have my table displaying users, and I have a external form to add new users using regular methods outside of the scope of datatables, I'm just looking a way to refresh the table once I create a new user without having to reload the browser.

    Does it make any sense?

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    I would really need to see an example of your code.

  • andrew1986andrew1986 Posts: 12Questions: 5Answers: 0

    hehehe the thing is, this is exactly my code:

    var my_table = $('#table').DataTable({ data: data, columns: [ { data: 'user', className: "user" }, { data: 'pw', className: "password" }, { data: 'other Info', className: "other" } ] });

    It renders perfect the table, however, let's say someone add records to the database on the background, so I need a refresh button where I can click and call the data again w/o refreshing.

    does it make sense?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    From that, your data is being loaded from the DOM, rather than by Ajax. Therefore, you will need to clear the table (clear()) and then Ajax load the new data and add it to the table with rows.add().

    If you were using Ajax loaded data for the table you could have just used ajax.reload().

    In future, please link to a test case showing the issue, as required in the forum rules, so we will be able to understand and answer your question - speeding things up for everyone.

    Allan

This discussion has been closed.