Angular directives and filters for sorting table rows
npm install @shagstrom/angular-sortable-tableDirectives and filter for creating a sortable table.
Install with
bower install angular-sortable-table
or
npm install @shagstrom/angular-sortable-table
Directives, filter and service is documented below the complete example.
A working example can be found here.
| Name | Age | Country |
|---|---|---|
| {{person.name}} | {{person.age}} | {{countryMappings[person.countryCode]}} |
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:
| Name | Age |
|---|---|
| {{person.name}} | {{person.age}} |
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:
| Name | Country |
|---|---|
| {{person.name}} | {{countryMappings[person.countryCode]}} |
Basic filter for sorting table rows based on sortObject.
Usage:
| Name |
|---|
| {{person.name}} |
Service containing helper functions.