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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lynx-datagrid

v0.1.4

Published

APIs to display grid and table data

Readme

Datagrid

The Datagrid module defines a simple API to display any type of data that can be sorted and (or) paged.

Multiple datagrid can be displayed in the same page, each with its own page and order status.

Moreover, the module is agnostic about the type of the data, how to retrieve it and how the data needs to be displayed. In this way, it can be easily adapter for any situation.

Usage

The Datagrid API is divided in two parts: the controller part and the view part.

Controller part

The Datagrid class contains the logic to parse and manage the paging and ordering arguments. Each Datagrid class needs to be created with a prefix values, in order to support multiple instance on the same page, without variable conflict. Once the setup of the instance is done, it is necessary to invoke the fetchData method, using an executor callback in order to retrieve the correct data.

let datagrid = new Datagrid<Person>("d0-", req);

await datagrid.fetchData((params) =>
    Person.findAndCount({ take: params.take, skip: params.skip, order: params.order })
);

The executor callback is invoke with a param argument, which contains the following properties:

  • take: the number of elements to be displayed in the page;
  • skip: the number of elements to be skipped;
  • order: an object containing the name of the property by which the data needs to be ordered; the value of this property can be 'ASC' or 'DESC'.

This parameters can be directly used in the findAndCount method defined by TypeORM.

The executor callback shall return the total size of the elements (needed to create a correct pagination) and the actual elements to be visualized.

The complete instance of the Datagrid class needs to be passed to the context of the rendered page.

View part

The module defines some Nunjuks macros to helps the data displaying. Moreover, the data retrieved by the Datagrid class needs to be displayed. A typical method to display the data is the following:

{% import resolvePath('/datagrid/utility') as dgUtils %}

<table>
    <tr>
        <td> {{ dgUtils.orderableHeader('Id', 'id', datagrid) }}  </td>
        <td> {{ dgUtils.orderableHeader('First Name', 'first_name', datagrid) }}  </td>
        <td> {{ dgUtils.orderableHeader('Salary', 'salary', datagrid) }}  </td>
    </tr>
    {% for line in datagrid.data %}
        <tr>
            <td>{{line.id}}</td>
            <td>{{line.first_name}}</td>
            <td>{{line.salary}}</td>
        </tr>
    {% endfor %}
</table>
{{ dgUtils.pagination(datagrid) }}

By default, the orderableHeader needs font-awesome to correctly display the order icons.