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

@mikelgo/ngx-reactive-table

v0.0.1-beta-4

Published

A lightweight, responsive, reactive data-table component for Angular

Downloads

22

Readme

ngx-reactive-table

This library was generated with Nx.

TOC

Why this library?

This library has the goal to provide a lightweight, reactive and customizable table-component for Angular, leveraging the power of RxJs. The table is responsive by leveraging CSS-Grid. It should allow to use a powerful table-component with minimal configuration effort.

One of the reasons to publish this library is the possibility to provide easy customization in comparison to other table-components like Angular material or Ag Grid.

E.g. it is not possible out of the box to create a reusable Angular material table which has the ability to use different column templates/content for certain columns in some components using the table. To have this feature the developer needs e.g. to leverage content-projection techniques. From my experience this is a common use case and should be possible out of the box.

In comparison to Ag Grid ngx-reactive-table can convice with a small bundle size. The Ag Grid packages shipd usually with > 20MB. Of course Ag Grid provides much more functionalities and is in general very powerful.

Quick start

TBD: add section to install the package.

First import NgxReactiveTableModule into your app.

The min. requirements to use the component is to provide three things:

  • a headerDefinition which describes the column titles,
  • a dataColumnDefinition which describes which property of a given data structure should be used to display the data,
  • a datasource providing static or dynamic data (e.g. from a HTTP call).
@Component({
  template: `
    <ngx-table
      [headerDefinition]="headerDefinition"
      [dataColumnDefinition]="dataColumnDefinition"
      [datasource]="datasource"
    >
    </ngx-table>
  `
})
export class TableHostComponent implements OnInit {
  public headerDefinition: TitleColumn[] = [
    { columnTitle: 'ID' },
    { columnTitle: 'Firstname' },
    { columnTitle: 'Lastname' }
  ];
  public dataColumnDefinition: DataColumn[] = [
    { displayProperty: 'id' },
    { displayProperty: 'firstName' },
    { displayProperty: 'lastName' }
  ];

  public datasource = new TableDataSource<Person>();

  constructor(private http: HttpClient) {};

  ngOnInit() {
    // Calling 'connect', connects the datasource to the table.
    this.datasource.connect([//...some static data]);

    // It is also possible to directly pass an observable to the
    // 'connect'-method. This is e.g. helpful if you have an observable
    // from an HTTP-reuqest.

    const data$ = this.http.get('some-endpoint');
    this.datasource.connect(data$);
  }
}

interface Person {
  id: number;
  firstName: string;
  lastName: string;
}

Configuration

Table configuration

Several properties of the table can be customized by providing configuration-objects. The default configuration is:

const DEFAULT_TABLE_CONFIG: TableConfig = {
  headerConfig: DEFAULT_HEADER_CONFIG,
  rowConfig: DEFAULT_ROW_CONFIG,
  width: '100%',
  maxBodyHeight: '300px',
  defaultColumnWidth: '1fr'
};

const DEFAULT_HEADER_CONFIG: HeaderConfig = {
  titleRowHeight: '50px',
  titlePositioning: TitlePositions.CENTER_CENTER
};

const DEFAULT_ROW_CONFIG: RowConfig = {
  style: 'wide',
  striped: false
};

Every property can be overwritten by providing a custom config as table-input. It is of course also possible to switch configuration easy during runtime (e.g. to provide the possibility to toggle between wide/dense table rows).

Column configuration

In the Quick start-section we had a first look on how to define the columns, which should be used in the table.

Generally there are two types of columns: TitleColumn and DataColumn, both extending a Column.

A TitleColumn just defines a column which is shown in the table header. A DataColumn therefor is just a column holding some data.

Providing a custom template

To have a flexible table it is possible to provide a custom ng-template which will be rendered as cell-template instead of a the default cell.

To do so it is necessary to provide a template

<ng-template #customTemplate let-element="element">
  <div class="custom">
    {{ element }}
  </div>
</ng-template>

and assign it to the according column:

@Component({...})
export class TableHostComponent implements OnInit {}
  @ViewChild('customTemplate', { static: true }) customTemplate: TemplateRef<any>;

  ngOnInit() {
    this.dataColumnDefinition: DataColumn[] = [
    { displayProperty: 'id', template: this.customTemplate },
    {...}
  ]
  }

Open issues

Please have a look at the issues.

Contribution

If you want to contribute, please have a look at the guidelines.