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

ractive-datatable

v1.7.0

Published

Interactive datatable for ractivejs

Downloads

15

Readme

#ractive-datatable

Demo

Live Demo

Install

npm install ractive-datatable --save

Features

  • Minimal (3.45kb gzipped including styles, 1.71kb without)
  • Well designed default styling
  • Cell Editing
  • Pagination (incl. navigation buttons)
  • Filtering (with sexy highlights)
  • Sorting
  • Per-cell partials (new!)
  • Selection (new!) (wip!)

Usage

Add the datatable to your Ractive instance:

Ractive.extend({
    ...
    components: {
        datatable: require('ractive-datatable')
    },
    ...
});

Use it

<datatable data='{{data}}' on-edit='dataedited' config='{{config}}' filter='{{filter}}'></datatable>

Includes minimal styling under the class .ractive-datatable. Styles are included in the javascript and added to the page on load. If you don't want these styles in the javascript, require() src/datatable.js and handle the styles as needed.

To use a specific partial for a cell, create an inline partial expression inside the tag of the component:

<datatable data='{{data}}' on-edit='dataedited' config='{{config}}' filter='{{filter}}'>
    {{#partial timestamp}}
        {{ moment(this).fromNow() }}
    {{/partial}}
</datatable>

Will render every row in the "timestamp" column with the passed in partial (in this case formatting the timestamp using moment.js).

API

Properties

data

Array of Objects where each key is a column

editable

globally allow/disallow editing

filter

A string to filter the rows on. Searches through all cells with a case-insensitive RegEx and displays only rows that match. Cells with matches are highlighted.

dynamicColumns

If true (default), searches the entire data array looking for columns. If false, columns must be explicitly provided through the columns property. If you have a large number of rows this should be turned off for performance, but you will have to explicitly provide columns via the columns object.

columns

Determines the ordering of the columns and configuration for specific columns.

Each key on this object refers to column names. Configurable properties are edit, display, header & order. Key/column names are case-sensitive.

Example:

columns: {
    'name': {order: 0}, // `order` "bumps" the column, lowest value is left most. 
    'created': {edit: false},
    'someAnnoyinglyNamedThingFromThatCoworkerThatDrivesYouNuts': {header: 'Nicer Name'},
    'id': {edit: false},
    'hiddenField': {display: false},
    'anotherHidden': false, //shorthand for { display: false }
    'someOtherColumn': {order: 3},
}

If dynamicColumns is false, only columns configured here will display.

selectionMode

Either row or cell (WIP). Allows for rows to be selected on click

selection

An array of the currently selected objects from data

page

The current page

lastPage (readonly)

The last page or total number of pages

sortOn

Name of column to sort

sortMode

Either 'asc' or 'desc'

Methods

previousPage()

Go to the previous page

nextPage()

Go to the next page

gotoPage(page)

Go to the specified page

Events

edit: Dispatched when an edit is made. Sends the entire row and the field that is edited (useful for extracting specific information from the row that changed).

this.on('dataedited', function(row, field) {
    
    var change = {};
    change.id = row.id;
    change[field] = row[field];
    
    changes.push(change);
    
});

For other events you probably would be better off using Ractive's observers on your datatable instance and the property you want.

Open to PRs and stuff. I'm around.