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

rv-table

v1.1.4

Published

๐Ÿ“‹ Customizable, Virtualized Table Component For React.js

Downloads

2

Readme

Installation:

Install the package using NPM:

npm install --save RVTable

You must also install the class properties plugin for babel if you haven't already by running:

npm install --save-dev @babel/plugin-proposal-class-properties

Usage:

  • First, import the module as a dependancy in your react project:

import RVTable from 'RVTable'

  • Pass data to the table using the passedData prop. This must be an array of objects, with key names that will be referenced later in the columns.

  • The rest of the config options are passed as an object to the config prop.

  • Columns are specified with:


{

displayName: String : The name that shows on the visual table

fieldName: String : The field in passedData

}
  • An optional value property can be added. This must be a function with an argument to take in the data for the row. An example would be:


value: ( rowData ) => {

const name = rowData.name );

return `My Name Is ${ name }`;

}

${ name } references the data for that row.

  • Optional width property in the columns can be set in fr, px or %. If not a default of "1fr" is set.

  • A sorting property can be added, which will allow the column to be sorted via clicking on the column header. More on sorting can be found later in the readme.

  • The required property can be added to any column using required: true, which will cause the table to throw an error if every row doesn't include the data.

  • The virtualization property sets the height of the rows and the table, is passed as a number.

  • Debug mode can be turned on in the config using degbugMode: true, which will console log any missing data that is not required.

  • A selection box can also be added via selectionBox: true. This will set the state of the row in the table selected = true, which you can extend upon for more features.

Example:

<RVTable

passedData={

[

{

user_id:  "1",

user_name:  "Mac",

email_address:  "[email protected]",

},

{

user_id:  "2",

user_name:  "Dennis",

email_address:  "[email protected]",

},

{

user_id:  "3",

user_name:  "Dee",

email_address:  "[email protected]",

},

{

user_id:  "4",

user_name:  "Charlie",

email_address:  "[email protected]",

},

{

user_id:  "4",

user_name:  "Frank",

email_address:  "[email protected]",

},

]

}

config={{

columns: [

{

displayName: "ID",

fieldName: "user_id",

required: true,

},

{

displayName: "Name",

fieldName: "user_name",

value: ( rowData ) => {

const  name = rowData.user_name;

return `Hello  My  Name Is ${ name }`;

},

},

{

displayName: "Email",

fieldName: "email_address",

},

],

debugmode: true,

selectionBox: true,

virtualization: {

tableHeight: 500,

rowHeight: 50,

},

}}

/>

passedData={

[

{

user_id: "1",

user_name: "Mac",

email_address: "[email protected]",

},

{

user_id: "2",

user_name: "Dennis",

email_address: "[email protected]",

},

{

user_id: "3",

user_name: "Dee",

email_address: "[email protected]",

},

{

user_id: "4",

user_name: "Charlie",

email_address: "[email protected]",

},

{

user_id: "4",

user_name: "Frank",

email_address: "[email protected]",

},

]

}

config={{

columns: [

{

displayName: "ID",

fieldName: "user_id",

required: true,

},

{

displayName: "Name",

fieldName: "user_name",

value: ( rowData ) => {

const name = rowData.user_name;

return `Hello My Name Is ${ name }`;

},

},

{

displayName: "Email",

fieldName: "email_address",

},

],

debugmode: true,

selectionBox: true,

virtualization: {

tableHeight: 500,

rowHeight: 50,

},

}}

/>

Virtualization:

By default, the table renders +5 rows on each side of the displayed data to ensure smooth scrolling. The table also lazy loads the fields in view, then half of the table, then the whole table to ensure high performance.

Sorting:

By adding the sorting property to a column config, RV Table will append a sorting icon to the header which can be toggled by clicking on the header.

There are three modes for sorting: Default, Function & Template.

  • Passing any non-falsy value to the sorting property will allow you to sort with the default mode, which converts cells to strings and sorts them using the javascript .sort() function.

  • Passing a function allows you to define your own comparison algorithm. The function has access to (rowA[propertyToSort], rowB[propertyToSort], rowA, rowB). Your comparison algorithm must have at least two args & return 0 1 or -1

  • Passing a string allows you to check the templating database for a sorting algorithm.

  • A div (which can be styled using pseudo elements) is appended before headers that have been sorted. The CSS class depends on the state.

.rv-table-indicator__ascending
.rv-table-indicator__descending
.rv-table-indicator__none

Current templates:

  • Date (sorting algorithm for dates)

  • Default (default sorting algorithm)

The sorting will fallback to the default algorithm if the passed sorting function is invalid, or if the sorting template can't be found in RV Table's store & an error message will be displayed

Styling:

  • RVTable fills 100% of the width of its parent container - therefore a wrapper is recommended around the table to control the width.

  • RVTable's styling is structured using BEM methodology, available selectors are:

.table
.table__header
.table__inner (Good for scrollbar styling)
.table__grid
.table__row
.table__cell

Gotchas:

  • It is recommended not to specify a field value or required attribute on any row that uses value, as it may result in unexpected behaviour. It shouldn't be necessary to do this, as the cell will take the data for that row & any error handling can be done in the function you pass the cell.

  • The test suite (Jest) will uses data-testid to select elements for testing.