Using the several jQuery library versions in one project with DataTables Editor.

Using the several jQuery library versions in one project with DataTables Editor.

vskripachevvskripachev Posts: 1Questions: 1Answers: 0
edited January 2022 in Editor

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown: Uncaught TypeError: $.fn.dataTable.Editor is not a constructor
Description of problem:

I'm trying to figure out the possibility to use DataTables Editor in our project.
We are using the old version jQuery with Bootstrap libraries for our project and tying to accommodate DataTables to the project.

I've installed the datatables.net-editor with the npm packager and updated *.js files with the install.js script from the trial version, downloaded from the website. The trial version not expired yet. I've download it a couple days ago.

I was able to make the DataTable working with the next code:

var $j = jquery.noConflict();
  $j(function () {
    $j("#datatable-example").DataTable({
      ajax: "/data/objects.json",
      columns: [
        { data: "name" },
        { data: "position" },
        ...
        { data: "salary" },
      ],
   });
});

But when I'm trying to use DataTable Editor from an example:

        var $j = jquery.noConflict();
        $j(function () {
            var editor = new $j.fn.dataTable.Editor({
                ajax: "/data/datatable-editor-objects.json",
                table: "#datatable-editor-example",
                fields: [
                    {
                        label: "First name:",
                        name: "first_name",
                    },
                    {
                        label: "Last name:",
                        name: "last_name",
                    },
                          ...
                    {
                        label: "Salary:",
                        name: "salary",
                    },
                ],
            });

, it is throwing the error for me:

"Uncaught TypeError: $j.fn.dataTable.Editor is not a constructor".

From the stack of function invocations I see it is using the proper latest version of jQuery (3.6.0).
Is it issue with the DataTables Editor package or an issue with the jQuery versions compatibility?

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

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

    Hi,

    That suggests to me that the jQuery you are running noConflict on is not the one that Editor was attached to. I'd need to be able to see the code for the page to understand what is going on fully though.

    I should note that Editor and DataTables will work fine with old versions of jQuery - they should work okay right back to v1.7 if you really need that (although the latest 1.x would obviously be best). What is your old version?

    Allan

Sign In or Register to comment.