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

ngx-cell-selectable

v1.0.8

Published

An Angular directive makes table cells selectable and copyable.

Downloads

19

Readme

ngx-cell-selectable

An Angular directive makes table cells selectable and copyable.demo

Install

You can get it on npm.

npm install ngx-cell-selectable

Open your module file e.g app.module.ts and update imports array

import { NgxCellSelectableModule } from 'ngx-cell-selectable';
...
imports: [
...
    NgxCellSelectableModule,
...
]

Usage

To make the cells selectable, you must disable the default selection function, define class e.g:

.disable-select {
    -moz-user-select: -moz-none;
    -moz-user-select: none;
    -o-user-select: none;
    -khtml-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

And define the class to be rendered when you select the cells; e.g:

.eng-selected-cell {
    background-color: #438eb9  !important;
    color: #fff !important;
    > * {
        color: #fff !important;
    }
}

Next, in your component .ts, add the four most important properties as the input properties of the directive, e.g:

import { CellSelectionInfo } from 'ngx-cell-selectable';

...
  cellSelectionInfo = new CellSelectionInfo();

  columns = [
    { binding: 'index', title: 'name' },
    { binding: 'name', title: 'name' },
    { binding: 'age', title: 'age' },
    { binding: 'address', title: 'address' },
  ];

  data = [];

  valueProp = 'binding'

and in component .html, Set these four properties to the table, e.g:

  <table tabindex="-1" hidefocus="true" [ngxCellSelectable]="cellSelectionInfo" [data]="data" [valueProp]="valueProp"
  [columns]="columns">
  ...
  </table>

Tip: In order for the table to be focused, it is also necessary to add the attribute tabindex="-1" hidefocus="true" to the table tag.

The next step is to use *ngFor to loop table columns and table data, set the ID of td according to the row index and column index(It's important!), e.g:[id]="rowIndex + '-' + colIndex", and use ngClass in td to set the class to use when the cell is selected, e.g:

  <tr>
    <th *ngFor="let c of columns" width="200px">{{ c.title }}</th>
  </tr>
  <tr *ngFor="let item of data; let rowIndex = index" class="disable-select">
    <td *ngFor="let c of columns; let colIndex = index" 
    [id]="rowIndex + '-' + colIndex" 
    [ngClass]="{'eng-selected-cell': cellSelectionInfo.selectionSet.has(rowIndex + '-' + colIndex)}">{{ item[c.binding] }}</td>
  </tr>

Finally, through cellSelectionInfo to get the selected relevant information, including how many items are selected, the average, and summary. In cellSelectionInfo.selection, you can get the id and value of the selected item (from data), e.g:

<div *ngIf="cellSelectionInfo.agg.cnt > 1; else cntAll">
        cntAll: <span>{{ cellSelectionInfo.agg.cntAll }}</span>;
        avg: <span >{{ cellSelectionInfo.agg.avg | number: '1.0-2' }}</span>;
        sum: <span>{{ cellSelectionInfo.agg.sum | number: '1.0-2' }}</span>;
</div>
<ng-template #cntAll>
    cntAll: <span>{{ cellSelectionInfo.agg.cntAll | number: '1.0-2' }}</span> 
</ng-template>

Input & Output

Properties | Description | Value :----------- | :----------- | :----------- [ngxCellSelectable] | The attribute that controls whether the cell can be selected. If you want to enable the selected cell function, pass in CellSelectionInfo, otherwise, pass in false to close the selectable function | CellSelectionInfo or false [data] | Table data Array | any[] [columns] | Table Column Array | any[] [valueProp] | The attribute name corresponding to the value to be selected in the column object | string (cellSelectionInfoChange) | After cellSelectionInfo Changed | EventEmitter<CellSelectionInfo> (copy) | After copied | EventEmitter<string>

License

MIT