Getting error "$.fn.dataTable.Editor is not a constructor" while using inline editor

Getting error "$.fn.dataTable.Editor is not a constructor" while using inline editor

SandSand Posts: 6Questions: 0Answers: 0
edited July 2015 in Free community support

My code is as follows:

$(function() {
$.ajax({
type: "GET",
url:"/textbook/list",
dataType: "json",
....... # code for listing text books
Book.BookList();
});

var Book = {
'init' : function() {
},
'BookList' : function() {

     ..... code for listing book list 

    var editor = new $.fn.dataTable.Editor( {
          "ajax": {
            "url" : 'textbook' + Book.book_code,
             fields: [ { 
            label: "Book name",
            name:  "book_name"
        }, {
            label:     "Title:",
            name:      "book_tiltle"
        }


    } );
   Book.dataTable = $('#book-datatable').dataTable( {
    "ajax": {
            "url" : 'textbook' + Book.book_code,
             "dataSrc": function(json) {
                   return json.data;
            }
        },
    "responsive": true,
        "bSort" : false,
        "order": [],
        "columns": [
            { "data": "book_name"},
            { "data": "book_tiltle" },
            { "data": "price" },
             {
                sortable: false,
                "render": function ( data, type, full, meta ) {
                   return Book.save(full);
                }
            },
        ]

    } );
},

But I am getting the error "TypeError: $.fn.dataTable.Editor is not a constructor" .Please help

Replies

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    It sounds like the Editor code might not be getting loaded, or possibly multiple versions of jQuery are being loaded on the page and one is overwriting another that has Editor attached to it.

    Allan

  • SandSand Posts: 6Questions: 0Answers: 0
    edited July 2015

    While loading editor js, I am getting following error:

    uncaught exception: DataTables Editor - remote hosting of code not allowed. Please see http://editor.datatables.net for details on how to purchase an Editor license

    And before my datatables were working perfectly. The issue was with inline editing

  • SandSand Posts: 6Questions: 0Answers: 0

    I managed to load all js file, and included below code in my js

    var editor = new $.fn.dataTable.Editor( {
    } );

    but again getting the same error - " $.fn.dataTable.Editor is not a constructor"

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Have you purchased an Editor license?

  • SandSand Posts: 6Questions: 0Answers: 0
    edited July 2015

    Below code is working fine now. Thanks.

    var editor = new $.fn.dataTable.Editor( {
            ajax: '/textbook/' + Book.book_code,
            table: "#datatableid",
            fields: [ {
                    name: "book_name"
                }, {
                    name: "title"
                }, {
                    name: "price"
                }
            ]
            });
            $('#datatableid').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline( this );
            } );
            Book.dataTable = $('#datatableid').dataTable( {
            "ajax": {
                    "url" : '/textbook/' + Book.book_code,
                    "dataSrc": function(json) {
                            return json.data;
                    }
                },
            "responsive": true,
                "bSort" : false,
                "order": [],
                "columns": [
                    { "data": "book_name"},
                    { "data": "title" },
                    { "data": "price" },
                    {
                        sortable: false,
                        "render": function ( data, type, full, meta ) {
                           return Book.saveOptions(full);    ## Wrote to save values from the fields
                        }
                    },
                ]
    
            } );
        },
    
    
    

    But another issue I got, when I edit the field, will it save automatically?

    I have gone through the example - https://editor.datatables.net/examples/inline-editing/simple.html , it also doesn't save data

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    If you want to it save automatically when the field loses focus, use the form-options submitOnBlur option:

    editor.inline( this, { submitOnBlur: true } );
    

    Allan

This discussion has been closed.