0
\$\begingroup\$

I am using ngx-datatable to load large volumes of records. However, the larger the volume, the longer it takes. I read somewhere that you can speed it up by sorting then assigning it to the data source. Could someone please assist me with finding the best way to improve the performance of this process? Below is the code I am currently using.

recipient.component.html

<ngx-datatable #table class='data-table' [columns]="columns" [columnMode]="'force'" [headerHeight]="37" [footerHeight]="50" [rowHeight]="38" [reorderable]="false" [limit]="7" (activate)="onActivate($event, editContent)" [rows]='getRecipients()'> </ngx-datatable>

recipient.component.ts

recipients: Recipient[] = [];
ngOnInit() {
    this.deleted_recipients = [];
    this.adhoc.getAdhocDetails(this.adhocForm.get('create.campaignNo').value).subscribe(
      x => this.seedRecipients(x),
      err => this.general.error(err)
    );
  }

    seedRecipients(csvRecordsArr: Recipient[]) {
          for (let y = 0; y < csvRecordsArr.length; y++) {
            const recipient = csvRecordsArr[y];
            recipient.status = this.getStatus(recipient);
            this.recipients.push(csvRecordsArr[y]);
          }
          this.recipients = [...this.recipients];
          this.origRecipients = JSON.stringify(this.recipients);
          this.checkStatus();
        }

getRecipients(): Recipient[] {
      return this.recipients;
    }

service.ts

getAdhocDetails(campaignNo: string): Observable<Recipient[]> {
        return this.http.get<Recipient[]>(this.baseUrl + 'getAdhocDetails/' + campaignNo).map(res => res);
      }

API class

public async Task<IEnumerable<AdhocRewardInfo>> getAdhocDetails(string CampaignNo) {
             //this._context.Database.SetCommandTimeout(200);
             var details = await _context.AdhocRewardInfo.Where(e => e.CampaignNo == CampaignNo).ToListAsync();
            
return details; }
\$\endgroup\$
5
  • 2
    \$\begingroup\$ How large volume are you talking about? Is pagination an option for you? \$\endgroup\$ Sep 22 '21 at 12:22
  • 1
    \$\begingroup\$ The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How do I ask a good question?. \$\endgroup\$
    – BCdotWEB
    Sep 23 '21 at 7:24
  • \$\begingroup\$ @PeterCsala I am using Pagination already. So basically the ngx-datatable takes some time to load records. It takes too long to pull data from the database and then load data into the datatable. \$\endgroup\$
    – KP257
    Sep 23 '21 at 10:36
  • \$\begingroup\$ @PeterCsala in terms of how large. 157 000 records that consist of 4 entries per record. \$\endgroup\$
    – KP257
    Sep 23 '21 at 10:48
  • 1
    \$\begingroup\$ @KP257 You don't use pagination. Getting all data from the api and then applying pagination client-side is IMHO not true pagination (and in your case clearly not working), you need to request a subset of the data (plenty of examples of that are available online). \$\endgroup\$
    – BCdotWEB
    Sep 23 '21 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.