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.

2

2 Answers 2

1

try this link Datatables Plugin in Angular 6

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.