searchPanes error on default serverSide

searchPanes error on default serverSide

we0038we0038 Posts: 42Questions: 14Answers: 1
edited 1:50AM in SearchPanes

I keep getting this error message:
ajax is null

on this filedatatables.js
on this line

else if (ajax.url === '') {
     // No url, so don't load any data. Just apply an empty data array
    // to the object for the callback.
    var empty = {};
    DataTable.util.set(ajax.dataSrc)(empty, []);
    callback(empty);
}

After troubleshooting, I found out that having default value for serverSide is the reason

$.extend( true, $.fn.dataTable.defaults, {
    serverSide: true,
});

how to fix this while keeping the default serverSide: true,

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,680Questions: 26Answers: 5,019
    edited 2:04AM

    It sounds like you haven't defined ajax in the Datatables options. Server side processing requires the use of ajax to fetch the data. If you are not using ajax for the table data then remove the serverSide option.

    Kevin

  • we0038we0038 Posts: 42Questions: 14Answers: 1

    I do use ajax for all of my tables. Also all of them are serverSide: true that's why I have that set in datatables default.

    Just today, I tried to use searchPanes for the first time and got that error.

    The current solution is to remove serverSide: true from $.fn.dataTable.defaults and add serverSide: true to each table initialisation but I does not make sense why it breaks when I set it as default!

  • kthorngrenkthorngren Posts: 21,680Questions: 26Answers: 5,019

    Sorry I missed the fact you are using SearchPanes. The default options are applied to all Datatables on the page. The SearchPanes tables are Datatables. I can think of two options:

    1. Remove serverSide: true from the default options and apply to all Datatables.
    2. Use searchPanes.dtOpts to set serverSide to false, for example:
      searchPanes: {
        dtOpts: {
          serverSide: false
        }
      },
    

    Kevin

  • kthorngrenkthorngren Posts: 21,680Questions: 26Answers: 5,019
    Answer ✓

    Just realized you can do this:

    $.extend( true, $.fn.dataTable.defaults, {
      serverSide: true,
      searchPanes: {
        dtOpts: {
          serverSide: false
        }
      },
    });
    

    For example:
    https://live.datatables.net/qeguyota/1/edit

    But it might not work if you are setting other searchPanes options as I believe the default will be overwritten.

    Kevin

  • we0038we0038 Posts: 42Questions: 14Answers: 1

    Thank you Kevin,
    This solves the error message. However, searchPanes always empty.
    I ended up removing serverSide: true, from $.fn.dataTable.defaults then define it for each table individually.

Sign In or Register to comment.