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

angular-table-npm

v1.0.8

Published

Angular directive which allows to declare sortable tables and to add pagination with very little effort.

Downloads

363

Readme

angular-table Build Status

Angular directive which allows to declare sortable tables and to add pagination with very little effort.

Available via bower: bower install at-table

Features

  • Adds sorting to any column
  • Adds pagination
  • Implicitly renders cell contents by name convention and allows custom cell content if needed
  • Implicitly renders header titles by name convention and allows custom header content if needed

Dependencies

This directive depends on angular only. No jQuery or Bootstrap required! It has been tested on angular 1.2, but it should also work with 1.1 releases.

Usage Examples

See the live demo with usage examples here.

Walkthrough

Let's assume we have an array containing objects representing people. A person object has the following format:

{name: ..., age: ..., birthdate: ...}

The list contains about 100 entries and we would like to represent that data in a nice, sortable html table and eventually make it paginated so we don't have to scroll like a madman. With angular-table in our toolbelt, this task becomes easy. Let's write some markup:

  <table at-table at-list="people">
  <thead></thead>
  <tbody>
    <tr>
      <td at-implicit at-attribute="name"></td>
      <td at-implicit at-attribute="age"></td>
      <td at-implicit at-attribute="birthdate"></td>
    </tr>
  </tbody>
</table>

Result

This renders a simple html table with an automatically generated header, showing every entry in our list. Four attributes have been used that need further explanation:

  • at-table indicate that we want to use the angular-table directive to extend our table
  • at-list point to the data source in our scope
  • at-attribute the attribute in each object the respective columns are dedicated to
  • at-implicit implicitly render the content of each object's attribute defined in at-attribute

Our table looks kind of unspectacular by now, so let's use some css, assuming we have twitter bootstrap in our sources:

<table class="table table-striped" ...>...</table>

Result

Now that looks better! Next, let's make the birthdate column sortable. We want to see the youngest people first, therefore sort descending. We're also going to customize the content of the birthdate cell since the raw date format looks ugly:

<td at-attribute="birthdate" at-sortable at-initial-sorting="desc">
  {{item.birthdate.substring(0, 10)}}
</td>

Result

And thats it, our table is sortable by birthdate instantly! We can make the other columns sortable aswell, by using the at-sortable attribute only. Also, note how we removed the at-implicit attribute and rendered our own content by using a custom angular expression.

Our list of people is pretty long though, and we hate scrolling, so breaking up the table into smaller chunks and making it possible to go through it with a pagination would be cool. A task done within seconds: We need to define two additional keywords in our table ...

<table ... at-config="config" at-paginated>...</table>

... and add an additional element to our view ...

<at-pagination at-config="config" at-list="people"></at-pagination>

... and we end up with a sortable, paginated table!

Result

Contributing

Pull Requests

This directive is written in Coffee Script. If you want to contribute, please make sure to work on the coffee sources only. When you're done with your changes, two steps are required:

  1. Update the version in the Gruntfile
  2. Compile:
grunt coffee
grunt usebanner

Running the tests

The code for this directive is well covered with tests, which can be run with PhantomJS and Karma. Run npm install to install the required packages. Then, run karma start to run the tests. Make sure all the tests pass before you send a pull request.