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

odata-grid-service

v0.0.4

Published

The `GridService` is an abstract service class designed to facilitate interactions with OData REST APIs in Angular applications. It provides a comprehensive solution for managing grid data operations such as filtering, sorting, pagination, and data retrie

Downloads

3

Readme

GridService With PrimeNg Table

Overview

The GridService is an abstract service class designed to facilitate interactions with OData REST APIs in Angular applications. It provides a comprehensive solution for managing grid data operations such as filtering, sorting, pagination, and data retrieval. The service uses RxJS to handle state management and HTTP requests efficiently.

Key Features

  • Observable Streams

    • data$: Holds the current grid data as a BehaviorSubject.
    • totalCount$: Tracks the total number of items in the grid.
    • loading$: Indicates whether data is currently being loaded.
  • Query Options

    • select: Specify fields to be selected in the OData query.
    • expand: Define related entities to include in the OData query.
    • defaultFilter: Apply default filtering rules.
    • defaultSorting: Apply default sorting rules.
  • API Interaction

    • resourceUrl: The specific API endpoint for the resource.
    • baseUrl: The base URL of the API.
    • http: Utilizes Angular's HttpClient for HTTP requests.
    • pageState: Manages pagination state (skip, top, total).
    • filterString: Holds the current filter query parameters.
    • sortingString: Holds the current sorting query parameters.

Methods

read()

Initiates a data fetch based on the current state (pagination, filtering, sorting).

setData(data: T[])

Manually sets the grid data.

refresh()

Re-executes the last data fetch using the same query parameters.

onPageChange(state: any)

Updates the pagination state and fetches data accordingly.

onFilterChange(event: TableFilterEvent | any)

Updates the filter state and fetches data based on the new filters.

onSortChange(event: any)

Updates the sorting state and fetches data based on the new sorting order.

onClear()

Clears all filters and sorting options, then refreshes the data.

getMatchMode(matchMode: FilterMatchMode)

Maps PrimeNG's FilterMatchMode to OData match modes.

getFilterImplementation(field: string, matchMode: string, value: any, dataType: DataTypeEnum)

Constructs OData filter query strings.

generateQueryString()

Builds the complete OData query string based on the current state.

execute(refreshUrl = '')

Executes the HTTP request to fetch data using the generated query string.

Utility Interfaces and Enums

PageState

Interface representing pagination state:

  • skip: Number of records to skip.
  • top: Number of records to fetch.
  • total: Total number of records available.

DefaultSorting

Interface for default sorting configuration:

  • field: The field to sort by.
  • order: Sort order (1 for ascending, -1 for descending).

DefaultFilter

Interface for default filter configuration:

  • field: The field to filter by.
  • matchMode: The OData match mode (e.g., eq, contains).
  • value: The value to filter by.
  • dataType: The data type (e.g., string, number).

ODataMatchMode

Enum representing OData match modes for filtering:

  • EQ: Equal (eq)
  • NE: Not equal (ne)
  • LESS_THAN: Less than (lt)
  • LESS_THAN_OR_EQUAL_TO: Less than or equal to (le)
  • GREATER_THAN: Greater than (gt)
  • GREATER_THAN_OR_EQUAL_TO: Greater than or equal to (ge)
  • CONTAINS: Contains (contains)
  • STARTS_WITH: Starts with (startswith)
  • ENDS_WITH: Ends with (endswith)

DataTypeEnum

Enum defining the data types for filtering:

  • STRING: String data type.
  • NUMBER: Number data type.
  • DATE: Date data type.
  • FLOAT: Floating-point number data type.

Usage

To use the GridService, extend it in a concrete service class for a specific entity type. For example:

export class ProductGridService extends GridService<Product> {
  constructor() {
    super('products', 'https://api.example.com');
  }
}