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

@doubletrade/lit-datatable

v2.0.0

Published

lit-datatable is a material design implementation of a data table, powered by lit-element.

Downloads

3,472

Readme

CI Published on webcomponents.org

lit-datatable

lit-datatable is a material design implementation of a data table.

screen

Roadmap

Add some helpers.

Install

npm install @doubletrade/lit-datatable

Launch demo

npm run serve

Lint

npm run lint:javascript

Data

// Data from api
const data = [
  { fruit: 'apple', color: 'green', weight: '100gr' },
  { fruit: 'banana', color: 'yellow', weight: '140gr' }
];
// Conf to set order of column and visibility (can be dynamically)
const conf = [
  { property: 'fruit', header: 'Fruit', hidden: false },
  { property: 'color', header: 'Color', hidden: true },
  { property: 'weight', header: 'Weight', hidden: false }
];

Simple example

<lit-datatable .data="${data}" .conf="${conf}"></lit-datatable>

Simple example with sticky header

<lit-datatable sticky-header .data="${data}" .conf="${conf}"></lit-datatable>

With HTML header

Use native html from lit-html to render a custom header. Header can use value from data and property from conf.

const headerOfFruit = (value, property) => html`<div style="color: red;">${value}</div>`;
<lit-datatable .data="${data}" .conf="${conf}">
  <lit-datatable-column header="${true}" property="fruit" .html="${headerOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data

As header, use native html from lit-html to render a custom body.

const bodyOfFruit = (value, property) => html`<div style="color: red;">${value}</div>`;
<lit-datatable .data="${data}" .conf="${conf}">
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data and footer

A footer is available to catch size and page changed in order to relaunch the request to the backend.

<lit-datatable .data="${data}" .conf="${conf}">
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>
<lit-datatable-footer
  @size-changed="${this._handleSizeChanged}"
  @page-changed="${this._handlePageChanged}"
  .availableSize="${[5, 10, 25]}"
  totalPages="10"
  totalElements="24"
  size="25"
  page="0"
  language="en">
</lit-datatable-footer>

With HTML data and sorter

A default sorter is available, set a header column without html and type sort. The sort must be of the following form : property,direction, ex: fruit,asc.

<lit-datatable .data="${data}" .conf="${conf}" @sort="${this._sortChanged}" .sort="${sort}">
  <lit-datatable-column header="${true}" property="fruit" type="sort"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data and custom sorter

You can use a specific sorter is available in helpers.

const sort = key => (value, property) => html`
  <ld-header-with-sort
    language="en"
    data-property="${property}"
    @direction-changed="${this.handleSortChanged.bind(this)}"
    direction="${this._getSortDirection(this.sort, key)}">
    ${value}
  </ld-header-with-sort>`;
<lit-datatable .data="${data}" .conf="${conf}">
  <lit-datatable-column header="${true}" property="fruit" .html="${sort}"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

Custom style on a td

<lit-datatable-column column="${true}" property="fruit" columnStyle="padding: 0; min-width: initial;"></lit-datatable-column>

With HTML data and filter

<lit-datatable .data="${data}" .conf="${conf}" @filter="${this.filterChanged}">
  <lit-datatable-column header="${true}" property="fruit" type="filter" .filterValue="${this.filter}"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data, sort and filter

<lit-datatable .data="${data}" .conf="${conf}" @filter="${this.filterChanged}".sort="${this.sort}" @sort="${this.sortChanged}">
  <lit-datatable-column header="${true}" property="fruit" type="filterSort" .filterValue="${this.filter}"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data and choices filter

<lit-datatable .data="${data}" .conf="${conf}" @choices="${this.choicesChanged}">
  <lit-datatable-column header="${true}" property="fruit" type="choices" .choices="${this.availableChoices}" .selectedChoices="${this.choices}"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data and choices filter with value filtering

<lit-datatable .data="${data}" .conf="${conf}" @choices="${this.choicesChanged}">
  <lit-datatable-column header="${true}" property="fruit" enableFilter type="choices" .choices="${this.availableChoices}" .selectedChoices="${this.choices}"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

With HTML data and date filter

The format of startDate and endDate is a timestamp.

<lit-datatable .data="${data}" .conf="${conf}" @dates="${this.datesChanged}">
  <lit-datatable-column header="${true}" property="fruit" type="dateSort" .start="${this.startDate}" .end="${this.endDate}"></lit-datatable-column>
  <lit-datatable-column column="${true}" property="fruit" .html="${bodyOfFruit}"></lit-datatable-column>
</lit-datatable>

Testing Powered By SauceLabs