0

ngOnInit() {
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 2
    };
 
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 2
    };
    this.allservice.getUrl(this.listUserUrl)
    .subscribe(data=>{
      this.listUser=data.responseContents
   

    });
  }
  
  ## angular.json:
    "styles": [
              "src/styles.css",
              "node_modules/datatables.net-dt/css/jquery.dataTables.css"

            ],
            "scripts": [

 "node_modules/jquery/dist/jquery.js",
              "node_modules/datatables.net/js/jquery.dataTables.js"

            ]
<table datatable  [dtOptions]="dtOptions" class="row-border hover">
  <thead>
    <tr>
        <th class="text-center width-10"> Name
       </th>
      <th class="text-center"> User Name
           
      </th>
    
    </tr>
  </thead>
  <tbody>
    <tr  *ngFor = "let i = index ; let x of listUser ">
          <td class="text-center">{{x.name}}</td>
      <td>{{x.username}}</td>
   
         
    </tr>
  </tbody>
</table>

In this Iam trying to use datatable on first loading Im getting the data in table but If I do any sort r filter,pagenation it showing No data Found.I dont no where Im making mistake can any one help to solve this problem.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Thilagavathy
  • 29
  • 1
  • 10

2 Answers2

1

try this link Datatables Plugin in Angular 6

enter image description here

Sanjay kumar
  • 1,653
  • 12
  • 18
0

I was getting no data found even if rows were loaded above that message. I got it solved using dtTrigger as explained below.

Make sure you are putting [dtTrigger]="dtTrigger" inside table tag in template. dtTrigger: Subject<any> = new Subject(); as component property. And after calling service put this.dtTrigger.next(); to tigger datatable rendering.

prisar
  • 3,041
  • 2
  • 26
  • 27