Support fnOnParserError from server data #55

wants to merge 2 commits into


None yet
3 participants

This gives an option for users to define what to do when there's a parser error from server data, like for instance, letting the user know he must refresh the whole page (when session timed out).


DataTables commented Mar 22, 2012

While I can see the need for this - why not just use fnServerData to define your own Ajax call with suitable success and failure handlers?

Maybe because the default implementation of fnServerData is enough? Why should I copy/paste?


DataTables commented Mar 22, 2012

But its obviously not enough since you had to add this :-). I'll have a bit of a think about this and might include it in future.

Thanks very much for the pull request and contributing to DataTables!

Sure! :-)


DataTables commented Sep 16, 2012

Going to close this for now. I don't want to provide a proxy for each one of the options that jQuery supports for ajax requests, as it will impact the code base size of DataTables and increase what needs to be supported.

I think a better solution is perhaps needed to allow easy access to changing these properties, but proxying each parameter isn't a route I want to go down.

@DataTables DataTables closed this Sep 16, 2012

Darn this is just what I needed. So if the fnOnParserError patch is not going to be applied?
What should I put in my initialization code exactly to do it you say override fnserverdata for this. So I need to find out where fnserverdata is implemented copy paste that code and edit the dialog there... Seems like this above patch is something a lot of people can use...

Basically I've got a perfectly working datatable. But when the users session times out or when his account is blocked he's redirected to the login page.

Now the problem is when he uses any of the ajax functions (paginate,search) the redirect does not happen but he gets the json error (which is normal as it's not returning data but trying to redirect).

Also I've used a lot of datatables and now need to add this to many instances like these:

$(document).ready(function() {
  var aSelected = [];
  var devicesTable;

   devicesTable = $("#devices").dataTable({
    "sDom": '<"H"flr>t<"F"ip>',
    "sPaginationType": "bootstrap",
    "aaSorting": [[0,'asc']],
    "iDisplayLength": 10,
    "bProcessing": true,
    "bServerSide": true,
    "sServerMethod": "POST",
    "bJQueryUI": true,
    "bStateSave": true,
    //This should fix our cookie issues 400 bad requests once and for all ;)
    "fnStateSave":  function (oSettings, oData) {
                      localStorage.setItem( 'DataTables_dev_'+window.location.pathname, JSON.stringify(oData) );
    "fnStateLoad":  function (oSettings) {
                      var data = localStorage.getItem('DataTables_dev_'+window.location.pathname);
                      return JSON.parse(data);
    "bRetrieve": true,
    "sAjaxSource": $('#devices').data('source'),
    "aoColumns": [
                     {"sType": "numeric"},
                     { "bSearchable": false, "bSortable": false, "sClass": "align-center" },
                     { "bSearchable": false, "bSortable": false, "sClass": "align-center" } ],
    "oLanguage": {
                    "sUrl": "/<%=I18n.locale %>/datatables_translations"

    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                      if ( jQuery.inArray( $(aData[0]).text(), aSelected) !== -1 ) {
                      var id = aData[0]; //get id col regardless of sort order
                      $(nRow).attr('device_id', $(aData[0]).text() );



DataTables commented Sep 19, 2012

Use fnServerData as indicated here: - its just a jQuery Ajax call so you can specify an error function.

Perhaps DataTables should have an 'ajax' option in its configuration parameters which will extend and override the options it uses for the Ajax call. I'll look into providing that in 1.10 - reopening to investigate.

@DataTables DataTables reopened this Sep 19, 2012

Looking forward to this


DataTables commented Feb 10, 2013

This has now been added as part of the DataTables 1.10 work. There is now an ajax initialisation option which can be used as an object, which maps directly onto $.ajax. For example, to add an error handler:

$('#example').dataTable( {
    "ajax": {
        "url": "../data_sources/rubbish",
        "error": function () {
            // ... error processing code
} );

This will be part of the DataTables 1.10 release which I hope to have complete by the end of next month, but the latest is always in github.

Commit: 2b67880

@DataTables DataTables closed this Feb 10, 2013

DataTables added a commit that referenced this pull request Aug 31, 2015

Fix: Setting non-array data when DataTables has been told to expect a…
…n array results in a Javascript error. Although this is somewhat unexpected input, it is reasonable to expect DataTables to handle null values here, even although an empty array is much prefered.

- THis fixes DataTables/DataTablesSrc #55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment