0

I am using angular 6 and data tables plugin. I need to implement yadcf in it. Please help me implementing it. I have used yadcf-npm to install the package. but when I use it like yadcf.init(), it throws error init of undefined. I have jquery 2.2.4.

I have used angular data table: https://l-lin.github.io/angular-datatables/#/welcome

 import { Component, OnInit, AfterViewChecked, ElementRef, ViewChild } from '@angular/core';    
    import { Claims } from 'src/app/search-tickets/grid/Claims';    
    import { Subject } from 'rxjs';   
    import { yadcf } from 'yadcf-npm';   
    import { DetailsService } from 'src/app/search-tickets/details/details.service';  
    import { DataTableDirective } from 'angular-datatables';   
    import { AfterViewInit, OnChanges, AfterContentChecked } from '@angular/core/src/metadata/lifecycle_hooks';    
    declare var jQuery: any;   
    import * as _ from "lodash"; 
    @Component({
    selector: 'app-details',
    templateUrl: './details.component.html',
    styleUrls: ['./details.component.css']
    })
    export class DetailsComponent implements OnInit, AfterViewInit, AfterViewChecked{
    selectedItem4: any;
    status: any[];
    dropdownSettings4: { singleSelection: boolean; idField: string; textField: 
    string; selectAllText: string; unSelectAllText: string; allowSearchFilter: 
    boolean; };
    pageInfo: DataTables.PageMethodeModelInfoReturn;
    pagination: any;
    click: string;
    sortExpire: any;
    sortTotal: any;
    sortId: boolean;
    dropdownSettings2: { singleSelection: boolean; idField: string; textField: 
    string; selectAllText: string; unSelectAllText: string; itemsShowLimit: 
    number; allowSearchFilter: boolean; };
    dropdownSettings1: any;
    claimsDivision: any;
    dropdownSettings: any;
    trial: any;
    selectedItem :any[];
    selectedItems: any;
    selectedItems1: any [];
    new2: any;
    @ViewChild(DataTableDirective)
    datatable: DataTableDirective;
    //dtOptions: DataTables.Settings = {};
    dtOptions: any;
    claims: Claims[] = [];
    new1: any;
    dtTrigger = new Subject();
  selected = [];
  constructor(private el:ElementRef, private detailsservice: DetailsService) { 

  }

  ngOnInit(): void {  
    this.dtOptions = {
     lengthMenu: [ 5, 10, 25, 50, 75, 100 ],

     pagingType: 'full_numbers',
     pageLength: 5,

     dom: 'lBrtip',

     ordering: false,
     preDrawCallback: function( settings ) {
       //alert("hi");
     },
      buttons: [
        // 'columnsToggle',
        // 'colvis',
        { "extend": 'copy', "text":'<span class="glyphicon glyphicon-copy"></span>',"className": 'btn btn-default btn-xs',
         exportOptions: {
          modifier: {
              columns: 'visible'
          }
         }
        },
        { "extend": 'print', "filter": "applied", "text":'<span class="glyphicon glyphicon-print"></span>',"className": 'btn btn-default btn-xs'
        }
      ]
    };



    this.detailsservice.getClaimsData()
            .subscribe(claim => {this.claims = claim;
              this.status = _.uniqBy(this.claims, 'status');


            yadcf.init(this.dtTrigger,[{ column_number: 0, filter_type: 'range_date', date_format: 'mm-dd-yyyy' }]);
            this.dtTrigger.next();


    });
  }
}

Please help me. Thanks alot.

  • I changed the version of jquery from 3.3.1 to 2.2.4 following this thread https://stackoverflow.com/questions/39616477/getting-yadcf-for-datatables-to-work-in-angular-2-jquery-3 but didn't work out for me. – Sanskriti Routray Aug 08 '18 at 07:22
  • 1
    You need to post some code so that we have something to work with. – Shai Aug 08 '18 at 07:24
  • @Shai I have edited my question and added the code. Please have a look. – Sanskriti Routray Aug 08 '18 at 08:59
  • @SanskritiRoutray try to init datatables object on selector with id and then use that object inside the `init` method – Daniel Aug 09 '18 at 07:26

0 Answers0