DataTable js showing error message - yii2

DataTable js showing error message - yii2

YiiDeveloperYiiDeveloper Posts: 5Questions: 2Answers: 1

Hi, I am creating a project using yii2. I linked datatable js and css files using CDN. However, when i run project, i got following errors:

This question has accepted answers - jump to:

Answers

  • YiiDeveloperYiiDeveloper Posts: 5Questions: 2Answers: 1
    edited September 2016

    I found solution for error1 and erro2. I forgot to link another js file:
    "https://code.jquery.com/jquery-1.11.3.min.js"
    However, I cannot find solution for the third error

  • allanallan Posts: 63,352Questions: 1Answers: 10,444 Site admin

    If you link to the page I'd be happy to take a look. There error suggests that DataTables hasn't been loaded or jQuery has been loaded multiple times.

    Allan

  • YiiDeveloperYiiDeveloper Posts: 5Questions: 2Answers: 1
    edited September 2016

    code in my view file is as follow:
    <?php

    use yii\helpers\Html;
    use yii\grid\GridView;

    /* @var $this yii\web\View /
    /
    @var $dataProvider yii\data\ActiveDataProvider */

    $this->title = 'Members';
    $this->params['breadcrumbs'][] = $this->title;

    <?php > ``` ``` ?>
    Number Region District Name
    $(document).ready(function (){ $('#example').DataTable({ ajax: { url: 'table', type: 'POST', dataSrc: '', }, columns: [ { data: 'Number' }, { data: 'Region' }, { data: 'District'}, { data: 'Name' } ], select: true }); });

    I have created action controller called actionTable and linked it to the view file. The interesting thing is that the same formula worked for yii1.

  • YiiDeveloperYiiDeveloper Posts: 5Questions: 2Answers: 1
    edited September 2016 Answer ✓

    i found solution. There went something wrong with js file. Instead of using CDN, local js files was used. I added css and js file in appasset :
    public $css = [
    'css/site.css',
    'css/datatables.css',

    ];
    public $js = [
        'js/datatables.js',
        'js/datatable.js'
    
    ];
    

    As a result, I got result

  • allanallan Posts: 63,352Questions: 1Answers: 10,444 Site admin
    Answer ✓

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

    Allan

This discussion has been closed.