Error $.fn.dataTable.Editor is not a constructor

Error $.fn.dataTable.Editor is not a constructor

MazinMazin Posts: 6Questions: 1Answers: 1

I have downloaded the trial version of the Editor and trying to implement the same in my project. But I am getting an error $.fn.dataTable.Editor is not a constructor
I have followed the code in the examples and included all the scripts and css files in my system. still it is giving the error. Please help me to fix this asap

This question has accepted answers - jump to:

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    You will have to show your code.

  • MazinMazin Posts: 6Questions: 1Answers: 1
    edited July 2017
       '''<link href="css/bootstrap.min.css" rel="stylesheet"/>  
          <link href="css/jquery.datatable.min.css" rel="stylesheet" /> 
         <link href="css/buttons.datatable.min.css" rel="stylesheet" />  
       <link href="css/select.dataTables.min.css" rel="stylesheet" />  
         <link href="css/editor.dataTables.min.css" rel="stylesheet" />  
      <!--<script src="js/jquery-1.12.4.js"></script>--> 
    <script src="js/jquery-3.2.1.min.js"></script> 
         <script src="js/jquery.dataTables.min.js"></script> 
        <script src="js/dataTables.buttons.min.js"></script>  
        <script src="js/dataTables.select.min.js"></script>  
        <script src="js/dataTables.editor.js"></script> 
       <script src="js/bootstrap.min.js"></script>  '''
    

    The are the scripts and css i am using and below is my datatable editor code

    '''
    var editor;
    $(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
    "ajax": "/customers",
    "table": "#table_id",
    "fields": [ {
    "label": "Name:",
    "name": "name"
    }, {
    "label": "Address:",
    "name": "address"
    }
    ]
    } );
    $('#table_id').DataTable( {
    dom: "Bfrtip",
    "ajax": "/customers",
    columns: [
    { data: "name" },
    { data: "address" },
    ],
    select: true,
    buttons: [
    { extend: "create", editor: editor },
    { extend: "edit", editor: editor },
    { extend: "remove", editor: editor }
    ]
    } );
    }); '''

  • MazinMazin Posts: 6Questions: 1Answers: 1

    thanks anyways. it is fixed.

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Answer ✓

    This error can often be caused by multiple jQuery version's being loaded on the same page. The later ones will overwrite the earlier ones.

    Good to hear you've got it working now - how did you fix it?

    Thanks,
    Allan

  • MazinMazin Posts: 6Questions: 1Answers: 1

    Yes, as you said i was referring to the same js file 2 times, one in the inner page and in layout. One in the inner page i haven't noticed. :smile:

  • MazinMazin Posts: 6Questions: 1Answers: 1

    Right now I am facing another error Could you help me to figure it out ?

    Uncaught TypeError: Cannot read property 'oFeatures' of undefined

    '''

    var userEditor = new $.fn.dataTable.Editor({

        "ajax": "http://localhost:5050" + "/users_details",
        "table": "#table_users",
        "idSrc": "_id",
        "fields": [{
                "label": "First Name:",
                "name": "first_name"
            }, {
                "label": "Last Name:",
                "name": "last_name"
            }, {
                "label": "Email:",
                "name": "email"
            }, {
                "label": "Diet Plan:",
                "name": "diet_plan"
            }
        ]
    });
    
    $('#table_users').DataTable({
        dom: "Bfrtip",
    
        "ajax": {
            "url": "http://localhost:5050" + "/users_details",
            "dataSrc": ""
        },
        columns: [
                  {
                   data: null, render: function (data, type, row) {
                    // Combine the first and last names into a single table field
                    return data.first_name + ' ' + data.last_name;
                }},
            //{ data: "email" },
            {
                "data": "email", // can be null or undefined
                "defaultContent": "<i>Not set</i>"
            },
            //{ data: "diet_plan" },
            {
                "data": "diet_plan", // can be null or undefined
                "defaultContent": "<i>Not set</i>"
            }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit", editor: editor },
            { extend: "remove", editor: editor }
        ]
    }); '''
    
  • MazinMazin Posts: 6Questions: 1Answers: 1
    Answer ✓

    Yeah. Fixed it also.. :smile:
    '''
    buttons: [
    { extend: "create", editor: editor },
    { extend: "edit", editor: editor },
    { extend: "remove", editor: editor }
    ]'''
    this was the thing caused the issue. :smiley:

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Thanks for posting back. Good to hear you have it working now.

    Allan

This discussion has been closed.