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

@shagstrom/angular-sortable-table

v0.1.1

Published

Angular directives and filters for sorting table rows

Downloads

5

Readme

Angular sortable table

Directives and filter for creating a sortable table.

Install with

bower install angular-sortable-table

or

npm install @shagstrom/angular-sortable-table

Complete example:

Directives, filter and service is documented below the complete example.

A working example can be found here.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Angular sortable table example</title>
        <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
        <script src="bower_components/angular/angular.js"></script>
        <script src="bower_components/angular-sortable-table.js"></script>
        <style>
            th.sortable { cursor: pointer; }
            th.sortable:after { content: "\f0dc"; padding-left: 5px; font-family: FontAwesome; font-size: 12px; }
            th.sortable.asc:after { content: "\f0de"; }
            th.sortable.desc:after { content: "\f0dd"; }
        </style>
        <script>
            angular.module('angular-sortable-table-example', [ 'shagstrom.angular-sortable-table' ])
                .controller('MainCtrl', function ($scope) {
                    $scope.countryMappings = {
                        "GH": "Ghana",
                        "GQ": "Equatorial Guinea",
                        "GR": "Greece"
                    };
                    $scope.people = [
                        { name: "John", age: 34, countryCode: "GQ" },
                        { name: "Sahra", age: 36, countryCode: "GH" },
                        { name: "Desmond", age: 19, countryCode: "GR" },
                        { name: "Carole", age: 25, countryCode: "GH" },
                        { name: "Annie", age: 25, countryCode: "GQ" }
                    ];
                });
        </script>
    </head>
    <body ng-app="angular-sortable-table-example" ng-controller="MainCtrl">
        <h1>Angular sortable table example</h1>
        <table sortable-table="personSortObject" sortable-table-options="{ multipleColumns: true }">
            <thead>
                <tr>
                    <th sortable-column="name">Name</th>
                    <th sortable-column="age">Age</th>
                    <th sortable-column="countryCode:countryMappings[value]">Country</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="person in people | sortTable: personSortObject">
                    <td>{{person.name}}</td>
                    <td>{{person.age}}</td>
                    <td>{{countryMappings[person.countryCode]}}</td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

sortableTable

Directive for setting up a sortable table.

The attribut value is name of the sort object that will be added to scope. The name of the sort object will also be as search parameter name in the browser url.

The sort object has this format:

{
    sortItems: [ {
        field: 'name',
        dir: 'asc'
    }, {
        field: 'countryCode',
        dir: 'desc'
    }, 
        ...
    ],
    transformers: {
        countryCode: function ...,
        ...
    }
}

The following options are set using the sortable-table-options attribute:

Usage:

<table sortable-table="personSortObject" sortable-table-options="{ multipleColumns: true }">
    <thead>
        <tr>
            <th sortable-column="name">Name</th>
            <th sortable-column="age">Age</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in people | sortTable:personSortObject">
            <td>{{person.name}}</td>
            <td>{{person.age}}</td>
        </tr>
    </tbody>
</table>

sortableColumn

Directive for making a column sortable.

Basic usage sortable-column="name", where "name" is the field to sort on.

You can define a transformer, that is used in "sortTable" filter and can be used when writing you own sorting code.

The transformer will be parsed and "obj" and "value" will be available. The transformer is defined after ":" in the directive attribute value. All transformers will be found in the sortObject.

Usage:

<table sortable-table="personSortObject">
    <thead>
        <tr>
            <th sortable-column="name">Name</th>
            <th sortable-column="countryCode:countryMappings[value]">Country</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in people | sortTable:personSortObject">
            <td>{{person.name}}</td>
            <td>{{countryMappings[person.countryCode]}}</td>
        </tr>
    </tbody>
</table>

sortTable

Basic filter for sorting table rows based on sortObject.

Usage:

<table sortable-table="personSortObject">
    <thead>
        <tr>
            <th sortable-column="name">Name</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in people | sortTable:personSortObject">
            <td>{{person.name}}</td>
        </tr>
    </tbody>
</table>

SortableTableService

Service containing helper functions.