Any way to refresh the webpage when error is triggered?

Any way to refresh the webpage when error is triggered?

techaddicttechaddict Posts: 6Questions: 1Answers: 0

I keep on receiving error: "DataTables warning:table id=maintable - Requested unknown paramter '8' for row 193. For more information about this error, please se http://datatables.net/tn/4" whenever the table is not loaded properly due to unknown reason.

The solution to it is reload the webpage.

So is there any option to auto refresh the webpage whenever this type error is received?

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    The real solution is to follow the link to the error information, and find and fix the error.

  • techaddicttechaddict Posts: 6Questions: 1Answers: 0

    The erorr is due to malformed table. And fix to it is to refresh the page!

    I couldnot find how to refresh the page when that error occurs. So posted this.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    The erorr is due to malformed table.

    And your job is to discover why that is happening, and fix it.

  • techaddicttechaddict Posts: 6Questions: 1Answers: 0

    The page length is too long. So the best solution is to refresh the page.

    Can you just help me how I can trigger custom event when this warning is triggered?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You can use $.fn.dataTable.ext.errMode = 'throw'; to have DataTables throw a Javascript error when an error occurs. You could try/catch that and reload the page (note if you are using ajax you would need to make a custom Ajax call and catch the error in the callback since ajax is async).

    However,r I would agree with tangerine, the best fix would be to never get into this state. Rather than putting in a workaround, I would suggest investigating why there is an error in the first instance and fixing that (the error might occur on the reload for example, which could just result in an infinite reload loop!).

    Allan

  • techaddicttechaddict Posts: 6Questions: 1Answers: 0

    @allen thanks a lot.

    Yes I dont have ajax so this solution will work.

    Do we have any example on how $.fn.dataTable.ext.errMode = 'throw'; can be used?

  • techaddicttechaddict Posts: 6Questions: 1Answers: 0

    $.fn.dataTable.serrMode = 'throw';
    try {
    $("#maintable").dataTable({
    "columnDefs": [
    {
    "targets": [ 0, 6, 7 ],
    "orderable": false
    },
    {
    data: 'myPropertyWithMPostfix',
    render: function ( data, type, row ) {
    if(type != 'display') {
    return data.substr( 0, data.length-1 );
    } else {
    return data;
    }
    },
    "targets": 11
    }
    ],
    "bPaginate": false
    });
    }
    catch(err) {
    alert('Error');
    console.log('error');
    }

    });

    Is this correct implementation of what you said?
    And any way to check if this works or not?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Example: http://live.datatables.net/dovixemu/1/edit .

    To make sure it works - trigger an error :-) Set the columns.data option to something that doesn't exist for example.

    Allan

  • techaddicttechaddict Posts: 6Questions: 1Answers: 0

    Thanks a lot. This is what I was looking for.

This discussion has been closed.