get some errors when using datatables with laravel mix

get some errors when using datatables with laravel mix

iehongiehong Posts: 3Questions: 1Answers: 0
$ = jQuery = require('../lib/adminlte/components/jquery/dist/jquery.min');
require('../lib/adminlte/components/bootstrap/dist/js/bootstrap.min');
require('datatables.net');
require('datatables.net-bs');
require('../lib/adminlte/components/jquery-slimscroll/jquery.slimscroll.min');
require('../lib/adminlte/components/fastclick/lib/fastclick');
require('../lib/adminlte/dist/js/adminlte.min');
require('../lib/layer/layer');
$.ajaxSetup({
  headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});
stenTable = $('table#stenTable').DataTable({
  "lengthMenu": [10, 25, 50],
  "processing": true,
  "serverSide": true,
  "ajax": {
    "url": '/sten',
    "type": "POST",
    beforeSend: function (xhr) {
      xhr.setRequestHeader('X-CSRF-TOKEN', $('meta[name="csrf-token"]').attr('content'));
    },
    "data": {
      cmd: "gets"
    }
  },
  "columns": [
    {"orderable": false},
    {"orderable": false},
    {"orderable": false},
    {"orderable": false},
    {"orderable": false}
  ],
  "pageLength": 10
});

it get error

Uncaught TypeError: $(...).DataTable is not a function

i have been already set

mix.webpackConfig({
  module: {
    loaders: [{
      test: /\.js/,
      loader: 'imports?define=>false'
    }]
  }
});

in webpack.mix.js

when i set

$.fn.DataTable=require('datatables.net-bs');

it seen works fine. but i can not use stenTable.ajax.reload.

what`s wrong with this

Answers

  • iehongiehong Posts: 3Questions: 1Answers: 0

    when i set

    require('datatables.net-bs')(window,$);

    it get
    Uncaught TypeError: Cannot set property '$' of undefined

    i have tried many times

    it also get error like

    Module not found: Error: Can't resolve 'datatables'

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @iehong ,

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • iehongiehong Posts: 3Questions: 1Answers: 0

    the codes is all above.i haven`t use jquery twice

This discussion has been closed.