Socket
Socket
Sign inDemoInstall

@shagstrom/angular-sortable-table

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @shagstrom/angular-sortable-table

Angular directives and filters for sorting table rows


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
2.01 MB
Created
Weekly downloads
 

Readme

Source

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:

multipleColumns
true/false; for allowing sort on multiple columns

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.

Keywords

FAQs

Last updated on 12 Jun 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc