vishwas jadav
vishwas jadav

Reputation: 299

Datatable function is not defined

I am trying laravel This is my welcome.blade.php file.

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>


        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
        <link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">

        <style media="screen">
          .error{
            color: red;
          }
        </style>

    </head>
    <body>
        <div class="flex-center position-ref full-height">

            <div class="content">
                <div class="title text-center">
                    <h1>Laravel</h1>
                </div>
                <div class="container">
                  @yield('content')
                </div>
            </div>
        </div>

         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
         <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


        @stack('scripts')
    </body>
</html>

Now, this is my CountryList.blade.php I want to list Countries I inserted to be listed.

@extends('welcome')

@section('content')
<div class="search">
  {!! Form::open(['method' => 'GET','route' => ['countries.index'], 'class' => 'form-inline']) !!}
    <div class="form-group col-md-6">
      {!! Form::text('title', null, ['class'=> 'form-control', 'placholder' => 'Search Name']) !!}
    </div>
    <div class="form-group col-md-3">
      {!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
    </div>
  {!! Form::close() !!}
</div>

  <div class="country text-center">
    <table class="table" id="countriesTable">
      <thead>
        <tr>
          <th>Id</th>
          <th>Country</th>
          <th>Created Date</th>
        </tr>
      </thead>
      <tbody>

      </tbody>
    </table>
    <div class="pages">
    </div>
    <div class="links">
      <a href="{{ route('countries.create') }}">Add A new Country</a>
    </div>
  </div>
@stop

@push('scripts')
  <script>
    $(document).ready(function () {
      $("#countriesTable").Datatable({

      });
    });
  </script>
@endpush

And I am having the error :

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

If I am having trouble with data , I can understand but no matter in what order I keep this js it always gives this error. I changed .DataTable() to .dataTable() still it was same. All of the js are loaded in browser. Please Help.

Upvotes: 0

Views: 2074

Answers (1)

Arun
Arun

Reputation: 3731

Because javascript classes are case sensitive. Use below code

$("#countriesTable").DataTable({

});

Datatable plugin made the class in camel case and it will not work if the call is not in camel case.

Upvotes: 2

Related Questions