TypeError: $.fn.dataTable.Editor is not a constructor

TypeError: $.fn.dataTable.Editor is not a constructor

sts1sts1 Posts: 2Questions: 1Answers: 0
edited January 2019 in Free community support

Hi. Im want try to use trial editor. But i get error "Editor is not a constructor"
I take code from https://editor.datatables.net/examples/simple/simple.html

dataTables.editor.min.js is hosted on my local server. Also i checked with developer tools that all css and js are loaded.

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>datatables</title>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jqc-1.12.3/dt-1.10.19/b-1.5.4/sl-1.2.7/datatables.min.css"/>
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.4/css/buttons.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/select.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/editor.dataTables.min.css">
</head>
<body>
<table id="example" class="display" width="100%" cellspacing="0">
    <thead>
    <tr>
        <th></th>
        <th>First name</th>
        <th>Last name</th>
        <th>Position</th>
        <th>Office</th>
        <th width="18%">Start date</th>
        <th>Salary</th>
    </tr>
    </thead>
</table>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.1/js/buttons.print.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.js"></script>
<script type="text/javascript" src="assets/js/dataTables.editor.min.js"></script>
<script type="text/javascript" src="assets/js/edit.js"></script>
</body>

</html>

edit.js

var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {
    
    editor = new $.fn.dataTable.Editor( {
        table: "#example",
        ajax: "loadAjax.php",
        fields: [ {
            label: "First name:",
            name: "first_name"
        }, {
            label: "Last name:",
            name: "last_name"
        }, {
            label: "Position:",
            name: "position"
        }, {
            label: "Office:",
            name: "office"
        }, {
            label: "Extension:",
            name: "extn"
        }, {
            label: "Start date:",
            name: "start_date",
            type: "datetime"
        }, {
            label: "Salary:",
            name: "salary"
        }
        ]
    } );
    
    // Activate an inline edit on click of a table cell
    $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editor.inline( this );
    } );
    
    $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: "loadAjax.php",
        order: [[ 1, 'asc' ]],
        columns: [
            {
                data: null,
                defaultContent: '',
                className: 'select-checkbox',
                orderable: false
            },
            { data: "first_name" },
            { data: "last_name" },
            { data: "position" },
            { data: "office" },
            { data: "start_date" },
            { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
        ],
        select: {
            style:    'os',
            selector: 'td:first-child'
        },
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );

Can someone tell me where is a problem?

Answers

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

    There is nothing obvious there I'm afraid. Is it possible you are loading jQuery again later on in the page? That would have this effect since jQuery would overwrite itself.

    If its not that, can you link to the page in question so I can take a look please?

    Thanks,
    Allan

  • sts1sts1 Posts: 2Questions: 1Answers: 0

    I found older version(v1.5.6) of editor in my old project and it work perfectly with same code. So i think the problem is in v1.8.1 editor, because examples in php trial archive does not work too.
    Now i cant give link to page, i try to provide it later

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

    That would be great if you could. This page uses the Editor 1.8.1 release and doesn't appear to exhibit that behaviour.

    Allan

  • jnunderwoodjnunderwood Posts: 5Questions: 0Answers: 0

    I just downloaded the trial Editor-1.8.1 files and I am having the same problem. I have attached my code. I have been using DataTables for about a year (love it), and would like to buy the Editor, but I need to know I get it working first. Thank you.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Maybe clear the browser's cache?

    Just to try it I just downloaded 1.8.1 and upgraded my Editor 1.6.2 with it and it works. Wonder if its an issue when running in trial mode?

    Kevin

  • jnunderwoodjnunderwood Posts: 5Questions: 0Answers: 0

    Everything is being downloaded. I'm using Chrome's developer tools to confirm that. I suspect it is the trial version of Editor 1.8.1.

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

    I've just tried downloading the 1.8.1 trial and the files appear to be where they are meant to be.

    Are you seeing any other errors in the Chrome console (a 404 for example) or in your server's error log? Are you able to give me a link to your page so I can take a look?

    Thanks,
    Allan

  • jnunderwoodjnunderwood Posts: 5Questions: 0Answers: 0

    I have put my source code into a github repo: . Please let me know if there is anything else I can do to help track down this problem. Thanks.

  • jnunderwoodjnunderwood Posts: 5Questions: 0Answers: 0

    Allan got back to me by email. There was indeed something wrong with the Editor trial version that expires on February 15 (which is what mine was). He provided me an updated trial version which works. Thanks Allan!

  • irkrexxirkrexx Posts: 6Questions: 1Answers: 1

    I just downloaded the trial Editor-1.8.1 files and I am having the same problem too.
    I try to run the sample files and get an error: Uncaught TypeError: $.fn.dataTable.Editor is not a constructor.
    I try both PHP version and the JS

    Thank you.

  • irkrexxirkrexx Posts: 6Questions: 1Answers: 1

    It's working!!! Thank you!
    I downloaded the demo again. Changed files.

This discussion has been closed.