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

sorted-table-angular

v0.0.4

Published

An implementation of table in Angular that allows you to sort table by column. Clicking header of a column will sort that column. It will work on zoneless Angular projecrs.

Downloads

21

Readme

SortableTableAngular

An implementation of table in Angular that allows you to sort table by column. Clicking header of a column will sort that column. It will work on zoneless Angular projecrs.

To use it first import it in your component or module.

import { SortedTable } from "./sorted-table/sorted-table";
type inputCellData = {
  text: string, color: string, bgColor: string, width: string
}

@Component({
  selector: 'app-root',
  imports: [SortedTable],
  template : `<div id="tableContainer">
      <app-sorted-table [tableData]="tableData()" 
      [tableHeaders] = "tableHeaders()" [clickCell]="false" 
      (clickEvent)="clicked($event)"></app-sorted-table>
    </div>`,
  styles: `
    #tableContainer {
      position: absolute; width: 1000px; height: 1000px; 
      border: 1px solid purple;
    }

    :host {
          --headerBG: aqua;
          --headerColor: darkolivegreen;
          --headerBorder: 1px solid azure;
          --headerFont: italic  1.2rem  "Fira Sans", serif;
          --headerPadding: .5em;

          --cellBorder: 1px solid bisque;
          --cellTextAlign: center;
          --cellPadding: .5em;
          --cellLineHeight: 1em;
          --cellHoverColor: moccasin;
          --cellBackground: lemonchiffon;
          --cellbackgroundAlternative: lightcyan;
          --cellFont: 1rem  "Fira Sans", sans-serif;

          --tableHeight: 100%;
      }
  `
})
  • [tableData]: It is the main content of your table. It will accept siganl of two dimensional array of string or inputCellData type. If you use inputCellData type, you can specify text color, background color of individual table cells. You can also set width. However width property effects whole column. Each cell is implemented using [innerHTML]. So you can pass html tags like <u> or <strong> for basic styling. However you cannot use <style> or <script>.

  • [tableHeaders]: It is the header row of your table. It will accept a signal of an array of strings.

  • [clickCell]": Set it to true if you want an event to fire every time a cell in table is clicked.

  • (clickEvent): Pass in a funtion you want to run every time a cell in table is clicked. The function will not run if [clickcell] is set to false. Function argument is an object with then type {row: number, column: number, text: string}. This object contains row value, column value and text of the cell that was clicked.

In the css of the component where this table is implemented, you can set these css variables that effect the style of the table.

  • --headerBG: Background color of the header row

  • --headerColor: Text color of header row

  • --headerBorder: Border style of header row

  • --headerFont: Font of the header row

  • --headerPadding: Padding around header row's text.

  • --cellBorder: Border style of table cells;

  • --cellTextAlign: Text alignment of texts in table cells.

  • --cellPadding: Padding around text of each cell.

  • --cellLineHeight: Line height text of each cell.

  • --cellHoverColor: Backgorund color of each cell upon mouse hover.

  • --cellBackground: Background color of odd numbered rows.

  • --cellbackgroundAlternative: Background color of even numbered rows.

  • --cellFont: Style of text of each cell.

  • --tableHeight: Height of the table in respect ot tge parent div.

Here is an example of full implementation of this component

import { Component, signal } from '@angular/core';
import { SortedTable } from "./sorted-table/sorted-table";
type inputCellData = {
  text: string, color: string, bgColor: string, width: string
}
type eventData = {row: number, column: number, text: string};

@Component({
  selector: 'app-root',
  imports: [SortedTable],
  template : `<div id="tableContainer">
      <app-sorted-table [tableData]="tableData()" 
      [tableHeaders] = "tableHeaders()" [clickCell]="false" 
      (clickEvent)="clicked($event)"></app-sorted-table>
    </div>`,
  styles: `
    #tableContainer {
      position: absolute; width: 1000px; height: 1000px; 
      border: 1px solid purple;
    }

    :host {
          --headerBG: aqua;
          --headerColor: darkolivegreen;
          --headerBorder: 1px solid azure;
          --headerFont: italic  1.2rem  "Fira Sans", serif;
          --headerPadding: .5em;

          --cellBorder: 1px solid bisque;
          --cellTextAlign: center;
          --cellPadding: .5em;
          --cellLineHeight: 1em;
          --cellHoverColor: moccasin;
          --cellBackground: lemonchiffon;
          --cellbackgroundAlternative: lightcyan;
          --cellFont: 1rem  "Fira Sans", sans-serif;

          --tableHeight: 100%;
      }
  `,
})
export class App {
  tableData = signal<string[][] | inputCellData[][]>([]);
  tableHeaders = signal<string[]>([]);
  words = [
    'quite', 'bake', 'sail', 'sugar', 'sweater', 'cactus', 'scissors', 
    'toothpaste', 'carpenter', 'tongue', "drink", 'earth', 'sneeze', 
    'cannon', 'cabbage', 'doll', 'zebra', 'quilt', 'carrot', 'sneeze',
  ]

  ngOnInit() {
    const data: string[][] | inputCellData[][] = []; 
    const headers = [];
    for (let i = 1; i <= 10; i++) {
      headers.push('header ' + i);
      const currentRow = [];
      for(let ii = 1; ii <= 10; ii++) {
        //Randomly entering words in the array
        currentRow.push(
          this.words[Math.floor(Math.random() * this.words.length)] 
          + ' ' + i + 'x' + ii
        );
      }
      (data as string[][]).push(currentRow);
      this.tableHeaders.set(headers);
    }

    // You can pass htmls tags for basic styling.
    data[1][1] = '<u>' + data[1][1] + '</u>'; 
    /*color and bgColor will only effect individual cell. 
    Width will effect whole column*/
    data[2][2] = {
      text: (data[2][2] as string), color: 'khaki', 
      bgColor: 'teal', width: '15%'
    }; 
    

    this.tableData.set(data);
  }

  clicked(event: eventData) {
    // This function will only fire if clickCell set to true
    console.log(event);
  }
}