How to replace error message and prevent upload?

How to replace error message and prevent upload?

responsivelabsresponsivelabs Posts: 31Questions: 8Answers: 0

Currently I’m allowing the user to upload a JSON file which is then translated into the datatable below it. However, if the user attempts to upload a file without the proper data, it will display a datatables error pointing it out and it will still send the data to the datatables.

My question is two parts: 1) how do I replace the system error with something more front end friendly, and 2) how do I prevent a file that triggers such an error from being sent to the datatable?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    Answer ✓

    how do I replace the system error with something more front end friendly

    You can handle errors using the error event and $.fn.dataTable.ext.errMode.

    how do I prevent a file that triggers such an error from being sent to the datatable?

    Not sure if there is a way to do this. Possibly a global variable used as an error flag could be used. Inside initComplete you can check the flag and clear the table if needed. There may be better ways but I built an example to show this:
    http://live.datatables.net/pinavuki/1/edit

    Kevin

  • responsivelabsresponsivelabs Posts: 31Questions: 8Answers: 0

    Awesome - I ended up just using the error event as you specified for now to remove the error. Thanks as usual Kevin!

This discussion has been closed.