question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Table only populates when clicking on sort field

See original GitHub issue

I am pulling data from a database and using angular 2 Observables to subscribe returned records and stored as objects in a local array variable. I implemented http.get() inside a service and subscribed the observable inside my component under ngOnInit(). For some reason the data is only being loaded when I click on a column title (i.e. on sort). Why am I not able to simple load the data?

I get no data found when I go to the webpage:

smarttable-no data found

When I click on a field, the data is loaded like so:

smarttablesedited

This is the code inside my component:

  initData(data) {
    this.allUsers = data;
    for(var i = 0; i < this.allUsers.data.length; i++) {
      if(this.allUsers.data[i].isactive == "true") {
        this.allUsers.data[i].isactive = "yes";
      } else {
        this.allUsers.data[i].isactive = "no";
      } 
      this.users.push({
        username: this.allUsers.data[i].username,
        firstname: this.allUsers.data[i].firstname,
        lastname: this.allUsers.data[i].lastname,
        lastloggedin: this.allUsers.data[i].lastloggedin,
        isactive: this.allUsers.data[i].isactive
      });
    }
  }


  subscribeUsers() {
    this._userService.getUsers()
    .subscribe(
        data => this.initData(data),
        error => this.handleError(),
        () => {

          this.source.load(this.users);
          console.log(this.source);
          console.log(typeof this.source);
          console.log("success");
      });
  }


  ngOnInit() { 
    this.subscribeUsers();
    console.log("show all users");
  }

This is the code inside my template:

`<div class="row"> <ba-card title="Users" baCardClass="with-scroll"> <ng2-smart-table [settings]=“settings” [source]=“users” (deleteConfirm)=“onDeleteConfirm($event)”></ng2-smart-table> </ba-card>

</div>``

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
radha89commented, Oct 27, 2016

Hi there. Calling those methods didn’t work for me when I tried. However, I managed to fix it. In the template inside <div> tag I just added: *ngIf="this.users.length > 0". That did the trick for me. Thanks for getting back to me though.

0reactions
victorwvieiracommented, Jan 11, 2022

Recently I had an experience using a smart-table component that some rows/data in the table just appears when the mouse hovers over the table or happens other interaction on the screen.

After investing some time in debugging I found the problem that create this strange behaviour. I’m using custom components and I developed some rules inside of these custom components, every time that these rules broke, the table stops loading the data and stay with this “hover” behaviour.

Solving the broken code inside of each custom component solved my problem and stopped this strange behaviour.

The broken code was a variable, type: number, using a string function like .toLowerCase() function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sort on clicking table header - angularjs - Stack Overflow
I have a table populated with data and added a extra column to the existing table which is the division of two fields....
Read more >
Sort records in custom order - Microsoft Support
On the Home tab, in the Sort & Filter group, click Advanced and then click Advanced Filter/Sort on the shortcut menu. Add the...
Read more >
Assigning row number for sorted table by column in QGIS
I have coded a plugin (Sort and Number) to solve your issue. It allows you to select up to 3 fields and order...
Read more >
Excel SORT function - auto sort data using formula - Ablebits
Apart from array generated by the FILTER function, we only specify the sort_index argument (column 2). The remaining two arguments are omitted ...
Read more >
How To: Sort and create a sequentially ordered ID field in an ...
Right-click the desired field in the attribute table. ... sortField = '[Base Field to sort]' idField = '[Field to populate sequential ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found