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

@brunojay/cell-edit

v1.1.0

Published

This package enables you to create editable table cells in angular

Downloads

12

Readme

CellEdit

Have you ever been faced with a challenge of editing cell data in a table within angular? Worry not, this package provides the most suitable solution.

Below is a detailed example of how you can use cellEdit to edit cell data in the available data types.

Data types supported currently

  1. text
  2. number
  3. date
  4. select - Editable Dropdown List
  5. telephone - Phone Number with Regex Validation

Installation

npm i @brunojay/cell-edit

How to Use - Example

  1. Import cellEdit into your component
import {CellEdit, OnUpdateCell} from "@brunojay/cell-edit";
  1. Implement AfterViewInit and OnUpdateCell on your component class
export class MyComponent implements AfterViewInit, OnUpdateCell {
  rows = [
    {
      id: "4af5a284-14c7-11ed-861d-0242ac120002",
      name: "John Wick",
      age: "45",
      dateOfBirth: "1977-08-18",
      telephone: "2424262626",
      course: "Agriculture",
    },
    {
      id: "4f2bd030-14c7-11ed-861d-0242ac120002",
      name: "Alexandar Dor",
      age: "25",
      dateOfBirth: "1997-09-01",
      telephone: "0773341425",
      course: "Engineering",
    }
  ]
}
  1. Add an Arrow Function called SaveCellValue to your component as shown below (Please take note of the syntax)
saveCellValue: any = (value: string, key: string, rowId: any): void => {
  if (this.rows.some(x => x.id === rowId)) {
    this.rows.forEach(function (item) {
      if (item.id === rowId) {
        item[key] = value;
      }
    });
  }
  console.log("value", value)
  //you will add more cases here depending on the cells you are editing
}

This is the method where you will be saving your new values using the row id of your record

  1. Add function for ngAfterViewInit to your component which will be called after the view has been rendered
ngAfterViewInit(): void {
  //create an instance of cell Edit
  let cellEdit = new CellEdit();

  //pick all td with cell-edit class name
  const cellsToEdit = document.getElementsByClassName('cell-edit');

  //create editable cells
  for (let i = 0; i < cellsToEdit.length; i++) {
    const cell = cellsToEdit[i] as HTMLElement;
  
    //create the other editable cells from here
    cellEdit.createEditableCell(cell, this.saveCellValue);
  }
}
  1. Edit your HTML component to add a div element as shown below
   <tr *ngFor="let row of rows">
      <td class="text-center cell-edit"
          data-key="name"
          data-type="text"
          id="{{row.id}}">{{ row.name }}</td>
      <td>...//add the rest here</td>
  </tr>

How it looks like

Text

Alt text

Date

Alt text

Detailed example and DEMO available here

https://cell-edit-ts.stackblitz.io/

Reach for more help or to contribute

Contact @brunoJay on github or email to [email protected]

License

This project is licensed under the MIT License - see the LICENSE file for details