Angular directive which allows to declare sortable tables and to add pagination with very little effort.
npm install angular-tableAngular directive which allows to declare sortable tables and to add
pagination with very little effort.
Available via bower: bower install at-table
``javascript`
{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:
`html`
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 extendat-list
our table
* point to the data source in our scopeat-attribute
* the attribute in each object the respective columns are dedicated toat-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:
`html`...
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:
`html`
{{item.birthdate.substring(0, 10)}}
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 theat-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 ...
`html`...
... and add an additional element to our view ...
`html`
... and we end up with a sortable, paginated table!
1. Update the version in the Gruntfile
2. Compile:
``
grunt coffee
grunt usebanner
to install the required packages. Then, run karma start` to run