Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82710

Difficulty installing Editor (in a localhost Ruby on Rails project during development)

$
0
0

Summary:

After installing Editor (I think), restarting my local server, I'm getting the following error initializing DataTable Editor [valid trial]:

[from console]:application.js:156 Uncaught TypeError: $.fn.dataTable.Editor is not a constructor
    at myAlert (application.js:156)
    at application.js:64

So after much searching I found out how to do the next step after
npm install datatables.net-editor.

1.I copied the Editor-1.9.6.zip file to the folder created by datatables.net-editor' and renamed itEditor.zip`

2.I then ran the install.js code:

my file hierarchy

output:

bobwalsh@iMac2021 FreelancerCashFlow2020 % node node_modules/datatables.net-editor/install.js node_modules/datatables.net-editor/Editor.zip
**Editor NPM install script
  Installing node_modules/datatables.net-editor/js/dataTables.editor.min.js
  Installing node_modules/datatables.net-editor/js/dataTables.editor.js
Done**

so, so far it looks good.

In my javascript/packs/application.js file I initialize jQuery, several other js libraries, and Datatables. so far, so good:

code to initialize Datatables (run from a timeout function after window loads)

let monthlies = $('#money_expenses').DataTable({
    paging: false,
    bFilter: false,
    searching: false,
    info: false,
    order: [[6, 'asc']],
    rowGroup: {
      dataSrc: 2,
    },
    columnDefs: [
      {
        targets: [0],
        orderable: false,
        className: 'select-checkbox',
      },
      {
        targets: [1],
        visible: false,
        searchable: false,
      },
      {
        targets: [6],
        visible: false,
      },
    ],
    select: {
      style: 'os',
      selector: 'td:first-child',
      style: 'multi',
    },
  })

Now all this works. Wonderful.

The problem is that while I do a require('datatables.net-editor') right after loading require('datatables.net-dt'), I still can't get DataTable Editor to initialize.

My code:

var editor = new $.fn.dataTable.Editor({
    ajax: '/api/staff',
    table: '#money_expenses',
    fields: [
      { label: 'First name', name: 'first_name' },
      { label: 'Last name', name: 'last_name' },
      // etc
    ],
  })

Results:

application.js:156 Uncaught TypeError: $.fn.dataTable.Editor is not a constructor
    at myAlert (application.js:156)
    at application.js:64'

I've tried running the code before my DataTables code, and after: the same message. What am I doing wrong?


Viewing all articles
Browse latest Browse all 82710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>