0

After taking time to read the new DataTable 1.10.2 API, I think I am getting better now. So far I have reduced my over 200 line code to just less than 100 and doing the same thing much better. Now I am stuck with the datatables not refreshing when a data changes. The code below refreshes only the .getJSON function but the datas not refreshed on the 2 tables in browser:

        $(document).ready(function (){
            var alertTable = $('#alert-table').DataTable({
                "columns": [
                    { "data": "host" },
                    { "data": "description" },
                    { "data": "value", "visible": false }
                ],
            });

            var errorTable = $('#error-table').DataTable({
                "columns": [
                    { "data": "host" },
                    { "data": "description" }
                ],

            });


            setInterval (function(){
                $.getJSON("data/json_data.txt", function (pcheckdata){

                    alertTable.clear();
                    alertTable.rows.add(pcheckdata.alerts).draw();
                    alertTable.columns.adjust().draw();

                    errorTable.clear();
                    errorTable.rows.add(pcheckdata.errors).draw();
                    errorTable.columns.adjust().draw();
                });
            }, 1000);
        });

This is what I see when i inspect firefox console:

GET data/json_data.txt 200 OK 10ms
3
  • your could tryout oTable.fnDraw(); after doing all your operations. Commented Sep 4, 2014 at 11:03
  • Thanks @D.T. i had identified the error. Commented Sep 4, 2014 at 11:06
  • nice one, easy updatable datatables :) Commented Sep 4, 2014 at 11:10

1 Answer 1

1

silly me, I just noticed my mistake, forgot to add .draw() after .clear()

                alertTable.clear().draw();
                alertTable.rows.add(pcheckdata.alerts).draw();
                alertTable.columns.adjust().draw();

                errorTable.clear().draw();
                errorTable.rows.add(pcheckdata.errors).draw();
                errorTable.columns.adjust().draw();
Sign up to request clarification or add additional context in comments.

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.