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

ng2-pack

v0.7.1

Published

A collection of components/utilities designed for data-intensive tables.

Downloads

27

Readme

Ng2Pack

A collection of components/utilities designed for data-intensive tables.

This library is currently under the development. API may still change! Please feel free to open issues not only for bug reports but also for ideas, comments, and questions, a.k.a. support requests. We would love to hear your feedback.

There are several key characteristics of the library:

  1. Levels of abstraction This library provides components with a varying level of abstraction. The highest abstraction gives you the most comfort. In the case that you need more flexibility, you can switch to lower API. If that is not enough, you access even lower-level API.

  2. Convention over configuration Despite many inputs and configuration options, you should be able to get running quickly because sensible defaults are preset or computed from the data. In some cases, even required inputs are automatically initialized for the subcomponents according to certain conventions.

  1. Fallback You can gradually migrate out of the library abstraction. It happens that library's abstractions are in the way. In that case, you can get full control by providing a custom template. The library accepts custom templates of different granularity.

Installation

You can install the package with yarn or npm.

yarn add ng2-pack

Then import the table module from 'ng2-pack'.

import { TableModule } from 'ng2-pack';
// import other modules (AppComponent, BrowserModule, ...) 

@NgModule({
  declarations: [AppComponent],
  imports: [
    TableModule,
    // list other modules...
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

We recommend that you install some CSS framework (e.g. Bootstrap) to enhance the style of the table.

Getting Started

We follow the philosophy "convention over configuration" to make it easier for you to get started. You can see it from the first code snippet.

NOTE: The examples in the demo app correspond to the following code snippets.

  1. Prepare your data — an array of objects (a.k.a. rows). Each row object can contain a nested object or an array of objects with simple data types (in other words, two levels of nesting are allowed). For example:
let rows = [{
    name: 'Alan',
    studies: [{
      university: 'TUM', 
      // additional attributes (degree, specialization, …)
    }, 
    // more study subrows 
    ],
    address: {
      country: 'cz', 
      // city, postal code …
    },
  }, 
  // more rows…
]
  1. Pass the data to rows input. Other attributes have intelligent defaults.
<iw-table #table [rows]="rows"></iw-table>
<!-- HINT: You can display how the column configuration was initialized: <pre>{{ table.columnsConfig | json }} </pre>   -->
  1. Adjust according to your needs. The most important attribute is the column configuration since the initialized values may not be exactly what you want. See the Table API section for the description of all input attributes and output events.
<iw-table
  [rows]="rows"
  [columnsConfig]="columnsConfig"
  [visibleColumns]="visibleColumns"
  rowsSortingMode="external"
  initialSortColumn="firstName"
  (rowClick)="onAction($event)"
  (sortColumnInit)="onAction($event)"
  (sortColumn)="onAction($event)"
  (addingColumn)="onAction($event)"
  (addColumn)="onAction($event)"
  (removeColumn)="onAction($event)"
  (visibleColumnsChange)="onAction($event)"
  >
</iw-table>
  1. Activate extensions
<iw-table [rows]="paginatedRows" [columnsConfig]="columnsConfig" rowsSortingMode="external">
</iw-table>
<iw-pagination #p [totalItems]="rows.length" (pageChange)="onPageChange(p.pageStart, p.pageEnd)" ></iw-pagination>
  1. Customize with your templates while using handy utilities and subcomponents. Here a custom template for body rows is defined. So that we can make table rows sortable (with directive iwSortableItem), and we use application-specific component to modify the look of a specific cell.
<iw-table
  [bodyRowTemplate]="bodyRowTemplate"
  [columnsConfig]="columnsConfig"
  [rows]="rows"
  #tableComponent>
  <ng-template #bodyRowTemplate let-row let-i="index">
    <tr iwSortableItem>
      <ng-template ngFor let-columnName [ngForOf]="tableComponent.visibleColumns">
        <td
          [class]="isCustomField(columnName)"
          *ngIf="!isCustomField(columnName)"
          iw-td
          [column]="tableComponent.columnsLookup[columnName]"
          [row]="row">
        </td>
        <td *ngIf="isCustomField(columnName)">
          <iw-studies-cell
            [row]="row"
            [column]="tableComponent.columnsLookup['studies']">
        </iw-studies-cell>
        </td>
      </ng-template>
      <td *ngIf="tableComponent.changeColumnVisibility"></td>
    </tr>
  </ng-template>
</iw-table>

Table API: Inputs

  • rows Data to be displayed in the table rows. Type: Row. The only required input.
  • columnsConfig Configuration of a table. Type?: ColumnConfig[].
  • visibleColumns Ids of initially visible columns in a table. Type?: string[]. Two-way data binding.
  • reorderingEnabled Enable/Disable drag&drop reordering of columns. Type: boolean.
  • changeColumnVisibility Enable/Disable user to select which columns are visible. Type: boolean.
  • rowsSortingMode By default, table rows are sorted client-side. You can use the external mode for server-side sorting. Lastly, the sorting of rows can be disabled completely (no sorting icons). Type: 'default' | 'external' | 'disabled'.
  • initialSortColumn Set column to be sorted on initialization. Optionally put plus or minus sign to specify the sort direction. Type: string.
  • bodyRowTemplate Specify a template to render for each body row.
  • headerRowTemplate Specify a template to render for table header row.
  • tableTemplate Specify a custom template for the whole table.

Table API: Output events:

  • addColumn A column was added by a user. Event data contain column id. Type: AddColumnAtPositionEvent
  • removeColumn A column was removed by a user. Event data contain column id. Type: RemoveColumnEvent
  • sortColumn A column was sorted by a user. Type: SortColumnEvent
  • addingColumn A column is being added at a specific position. Type: AddingColumnEvent
  • toggleSubfield Triggered when a visibility for a subfield is changed. Type: ToggleSubfieldEvent
  • visibleColumnsChange This event is trigged whenever a column is added/removed or the order changed.
  • rowClick Body row was clicked. Event data is row index. Type: RowClickEvent

Subcomponents

  • HeaderRowComponent
    • ThComponent
    • AddColumnComponent
  • Tbodyomponent
    • TdComponent

Licence

MIT