-
Notifications
You must be signed in to change notification settings - Fork 851
Configuring your table with ngTableParams
ngTable is configured through the use of an ng-table
attribute on a table element. The value of this attribute points to a scope property that represents an instance of ngTableParams. For example:
In your HTML:
<table ng-table="tableParams">
...
</table>
In your controller:
$scope.tableParams = new ngTableParams(parameters, settings)
When instantiating ngTableParams, the function takes two arguments: parameters
and settings
. Both are Objects and are detailed below.
The parameters
object should be used to define initial (set and forget) configuration. More complex configuration should be done in the settings
object. The following properties are available on the parameters
object.
type: Number, default: 1
The page number to show
type: Number, default: 1
The number of items to show per page
type: Object, default: {}
Defines filters for columns. Case insensitive. For example, given this set of data:
var data = [
{name: "Moroni", age: 50},
{name: "Tiancum", age: 43}
];
You can define a filter to only show rows containing a name of "Moroni" by setting filter
to:
{
name: "Moroni"
}
type: Object, default: {}
Defines sorting for columns. For example, given this set of data:
var data = [
{name: "Moroni", age: 50},
{name: "Tiancum", age: 43}
];
You can define an ascending sort order for the name column by setting sorting
to:
{
name: 'asc'
}
TODO
TODO
TODO
type: Function
Defines a method for collating the data that should be displayed in ngTable. getData
is always supplied with 2 arguments, $defer
and params
, as in the following example:
getData: function ($defer, params) {
...
}
$defer
is a Promise object. Resolve your data with $defer
's resolve method to make your data available to ngTable.
For example, given this set of data:
var data = [
{name: "Moroni", age: 50},
{name: "Tiancum", age: 43}
];
At the most basic level, you can make all data available to ngTable:
getData: function ($defer, params) {
$defer.resolve(data);
}
params
is a reference to the configuration supplied in the parameters
object (or ngTable's defaults, if not supplied in parameters
).
For example, to retrieve the current filter
and sorting
parameters:
getData: function ($defer, params) {
...
var filter = params.filter();
var sorting = params.sorting();
...
}