npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

table-helper

v0.0.8

Published

The Table Helper acts as a bridge between a PrimeNG table and a back-end service, simplifying the process of mapping and sending lazy load events for data retrieval on the front-end. It keeps the code clean and easy to maintain by handling the complex map

Downloads

80

Readme

Table Helper

The Table Helper acts as a bridge between a PrimeNG table and a back-end service, simplifying the process of mapping and sending lazy load events for data retrieval on the front-end. It keeps the code clean and easy to maintain by handling the complex mapping details. This service extracts relevant information from the event, such as filtering criteria, sorting preferences, and pagination details. The data is then transformed into a format suitable for a back-end request. The transformed parameters are passed to the provided loadDataService method for actual data retrieval from the back-end.

Table of contents

Installation

To use the Table Helper Service, you need to install it as a dependency in your Angular project. Run the following command in your project's root directory:

npm install table-helper --save

This will install the library and save it as a dependency in your project's package.json file.

Using the service

After installing the library, you need to import the Table Helper Service in your table component:

import { TableHelperService } from  'table-helper';

// ...

constructor(private tableHelperService: TableHelperService) {}

Lazy load & PrimeNg

In order to be able to use the service, lazy load functionality should be included in the table. It is used in cases when we need to load small chunks of data by invoking callbacks everytime for paging, sorting and filtering occurs. For more information on lazy load, open the following link https://primeng.org/table#lazy-load.

     1. Define a request method

Before proceeding to how to use the service for lazy loading data, we should define a method that will handle the request to the back-end in the following way:

loadDataService(tableSendDataParams: TableSendDataParams) {
  const sendDataParams = {
    ...tableSendDataParams
    // add any extra parameters specific to your use case
  }
  
  // Adjust this line according to your use case
  return this.aircraftService.getAircrafts(sendDataParams);
}

NOTE: TableSendDataParams has the following definition:

interface TableSendDataParams {
  filter?: string[];
  sort?: string[];
  page?: number;
  size?: number;
}

     2. Using the service

In order to be able to use the service, onLazyLoad event should be binded to the table:

<table [lazy]="true" (onLazyLoad)="loadData($event)">
  <!-- Table content goes here -->
</table>

Then, the loadData should be implemented in the following way:

loadData(event: TableLazyLoadEvent) {
  if (!this.loadDataService) {
    return;
  }
  
  this.tableHelperService.sendRequest(event, this.loadDataService).subscribe({
    next: result => {
      // handle result
    },
    error: err => {
      // handle error
    }
  });
}

As it can be seen in the example above, sendRequest accepts two parameters:

  • event - represents the TableLazyLoadEvent that is emitted when the onLazyLoad event occurs in PrimeNG table
  • this.loadDataService - refers to the method defined earlier (loadDataService) that handles back-end request

How to use with shared table component

When integrating the Table Helper Service with a shared table component, follow these steps:

     1. Define loadDataService

loadDataService method implementation is the same as shown in the previous section. However, the only difference is that it has to be defined in the component where the shared table component is used. In addition, ensure to bind this to loadDataService in ngOnInit in the following way: this.loadDataService = this.loadDataService.bind(this);:

ngOnInit() {
  this.loadDataService = this.loadDataService.bind(this);
}

     2. Pass loadDataService to shared table component

In the shared table component, you need to receive the loadDataService method as an input. This input property is used later in the loadData method, which is bound to the onLazyLoad event in the table. Add the following input property to your shared table component:

`@Input() loadDataService!: (params: TableSendDataParams) => Observable<any>;`

This is the loadDataService parameter that is passed to the service (see loadData method).