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

sm-table

v0.1.0

Published

mithril semantic-ui table datatable widget

Downloads

7

Readme

sm-table

Mithril semantic-ui data table widget

It requires mithril and semantic-ui-table, semantic-ui-loader and sm-pagination if you need pagination

Pagination file can be used with any common.js it is expect for mithril to be in global (m variable) or it will attempt to load it with require('mithril'), webpack its recommended

It can be used with bootstrap also, just pass the correct classes

Alt text

Demo

Demo

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.10.3/semantic.min.css">
    <script src="bower_components/mithril/mithril.js"></script>
    <script src="bower_components/sm-pagination/Pagination.js"></script>
    <script src="Table.js"></script>
</head>
<body>

    <script src="test.js"></script>
</body>
</html>
module.controller = function () {
    module.vm.init(array);
};
module.vm = {};
module.vm.init = function (data) {
    this.customers = data;
    this.rowsperpage = 10;
    this.table = new Table({
        columns: ['id', 'name'],
        data: data
    });
};
module.view = function (/*ctrl*/) {
    return m('.ui.grid.page', [
        m('h1', 'Basic Table'),
        m('.ui.sixteen.wide.column', [
            module.vm.table.view()
        ])
    ]);
};

m.module(window.document.body, module);

Attributes

It accepts the following properties, columns and data or url the only ones mandatory

  • columns, array of columns to display
  • data, data to display, should be an array
  • url, url to load the data
  • pagination, object with pagination options
  • filter, function to apply the filter
  • onclick, function to call when a cell is clicked
  • classes, object map with:
    • table, applied to the table, defaults ui table sortable
    • columnLoading, applied to the only column in the only row when the table its loding data, defaults center aligned
    • loader, applied to the div insdide the loading column when the able its loading data, defaults ui active loader inline
    • columnNoResults, applied to the only column in the only row when no results are being displayed, defaults center aligned
    • sortedAscending, applied to the header when is sorted ascending, defaults sorted ascending,
    • sortedDescending, applied to the header when is sorted descending, defaults sorted descending
    • notSorted, applied to the header when its not being sorted, defaults ``
    • disabled, applied to the disabled headers, defaults disabled

Coumns Definitions

The array of columns can be either an array of strings with the fields you want to display or an array of objects, that must have a field at least column:

  • field: field to get the text,
  • label: to display in the header,
  • format: function to format the cell/row, if you return something here this will be placed as text in the m function m('td', attr, text), the function receives
    • value, field value
    • object, current item object
    • celAttributesObject, column attrbiutes, these will be passed to the m function as m('td', attr)
    • rowAttributesObject, row attributes, these will be passed to the m function as m('tr', attr)
    • index, index of the current row
    • getterFunction, if you are passing a getter, this functino will be provided to get the same as the get
  • sort: sortable function that must return a function for the table sorting, if the column is sortable and there is no sort function, it will use a simple sorting, this function receives
    • key, current object field
    • ascending, boolean for ascending
    • getter, the get function for the current field
  • sortable: boolean to make the column sortable,
  • get: function to format the display value of the column, must return a string or an m element, it receives the current item object,
  • classes: class to apply to the column

Functions

Creating a table

var table = new Table({
    colums: ['id', 'name']
});

Loading the view table, you can pass data again to override the current data

m('div', table.view())
m('div', table.view(data))

You can jump to a page if the table is using pagination

table.goToPage(2);

You can get the cell, row or data from an event started inside the cells

table.getCell(e); //<td></td>
table.getRow(e); //<tr></tr>
table.getRow(cell); //<tr></tr>
table.getData(e); //Object

You can also update the data with

table.setData(data);