IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Angular Discussion :

[Datatable] Cannot read property 'dtInstance'


Sujet :

Angular

  1. #1
    Membre éclairé
    Inscrit en
    Juin 2005
    Messages
    578
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 578
    Par défaut [Datatable] Cannot read property 'dtInstance'
    Bonjour

    J'ai intégré datatables dans mon application Angular mais lorsque je lance l'application, j'ai ce message d'erreur:

    ListeCompteComponent.html:6 ERROR TypeError: Cannot read property 'dtInstance' of undefined
    at TblSearchingComponent.push../src/app/demo/pages/compte/liste-compte/tbl-searching/tbl-searching.component.ts.TblSearchingComponent.ngAfterViewInit (tbl-searching.component.ts:71)
    at callProviderLifecycles (core.js:22318)
    at callElementProvidersLifecycles (core.js:22292)
    at callLifecycleHooksChildrenFirst (core.js:22282)
    at checkAndUpdateView (core.js:23218)
    at callViewAction (core.js:23450)
    at execComponentViewsAction (core.js:23392)
    at checkAndUpdateView (core.js:23215)
    at callViewAction (core.js:23450)
    at execEmbeddedViewsAction (core.js:23413)
    Voici le code de mon fichier tbl-searching.component.ts:

    Code TypeScript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
    import {DataTableDirective} from 'angular-datatables';
    import {HttpClient} from '@angular/common/http';
    import 'rxjs/Rx';
    import { Observable } from 'rxjs/Rx';
    import { CommonModule } from '@angular/common';
     
     
    @Component({
      selector: 'app-tbl-searching',
      templateUrl: './tbl-searching.component.html',
      styleUrls: ['./tbl-searching.component.scss']
    })
    export class TblSearchingComponent implements OnInit, AfterViewInit {
      dtColumnSearchingOptions: any = {};
      @ViewChild(DataTableDirective)
      datatableElement: DataTableDirective;
     
     
      public isNoResult: boolean = true;  
      public empData: Object;
      public temp: Object=false;
     
      constructor( private http: HttpClient) { }
     
      ngOnInit(): void  {
    	 // this.reloadData();
    	 this.http.get('http://localhost:8080/gestion-scolaire/rest/compte/api/comptes').subscribe((resp: Response) => {
    	this.empData = resp;
    	this.temp = true;
      }); 
        this.dtColumnSearchingOptions = {
     
        //  ajax: 'fake-data/datatable-data.json',
          columns: [{
            title: 'firstName',
            data: 'firstName'
          }, {
            title: 'lastName',
            data: 'lastName'
          }, {
            title: 'job',
            data: 'job'
          }, {
            title: 'address',
            data: 'address'
          }, {
            title: 'email',
            data: 'email'
          }],
          responsive: true,
          dom: 'Blfrtip',
          buttons: [
            'copy',
            'print',
            'excel',
            'csv'
          ]
        };
      }
     
     
      ngAfterViewInit(): void {
        this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
          dtInstance.columns().every(function () {
            const that = this;
            $('input', this.footer()).on('keyup change', function () {
              if (that.search() !== this['value']) {
                that
                  .search(this['value'])
                  .draw();
              }
            });
          });
        });
      }
     
    }

    Voici le code de mon fichier tbl-searching.component.html:

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <table datatable [dtOptions]="dtColumnSearchingOptions" class="table table-striped row-border table-hover" *ngIf="this.temp">
     <tr *ngFor="let compte of this.empData ">
                    <td>{{compte.firstName}}</td>
                    <td>{{compte.lastName}}</td>
                    <td>{{compte.job}}</td>
                    <td>{{compte.address}}</td>
                    <td>{{compte.email}}</td>
                  </tr> 
     <tfoot>
      <tr>
        <th><input type="text" placeholder="Search firstName" name="search-firstName" class="form-control" /></th>
        <th><input type="text" placeholder="Search lastName" name="search-lastName" class="form-control" /></th>
        <th><input type="text" placeholder="Search job" name="search-job" class="form-control" /></th>
        <th><input type="text" placeholder="Search address" name="search-address" class="form-control" /></th>
        <th><input type="text" placeholder="Search email" name="search-email" class="form-control" /></th>
      </tr>
      </tfoot>
    </table>

    Voici le code de mon fichier liste-compte.component.html:

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <div class="row">
     
    <div class="col-sm-12">
        <app-card cardTitle="Column Searchings" [options]="false">
          <div class="table-responsive">
            <app-tbl-searching></app-tbl-searching>
          </div>
        </app-card>
      </div>
     
    </div>

    Merci

  2. #2
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2019
    Messages
    707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2019
    Messages : 707
    Par défaut
    le message est clair :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
    dtInstance est undefined !

Discussions similaires

  1. cannot read property ' ' of undefined - GWT Java
    Par alineas1 dans le forum GWT et Vaadin
    Réponses: 1
    Dernier message: 25/11/2015, 14h38
  2. Réponses: 3
    Dernier message: 30/05/2015, 12h08
  3. [V8] Importation csv Error Cannot read property '1' of undefined
    Par vernetk dans le forum Odoo (ex-OpenERP)
    Réponses: 1
    Dernier message: 11/02/2015, 16h36
  4. Réponses: 15
    Dernier message: 15/06/2013, 01h11
  5. sous Chrome TypeError: Cannot read property 'style' of null 7
    Par cfabc dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 03/08/2010, 12h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo