Filter and Sort
A WireBootstrap DataTable contains methods that allow its data to be filtered.
Basic Filters
In the example below, the row containing the user pdougherty
is pulled out of the data table. The first
method at the end of the filter chain evaluates the filter and returns the first row that meets the filter's criteria.
In the example below, all user rows are pulled except for the one containing the user pdougherty
. This is done using the ne
method instead of the eq
method used in the previous example. The rows
method at the end of the filter chain evaluates the filter and returns all rows that meets the filter's criteria.
Filters can be combined in a data table. The filter operations can also be broken at any point in the method chain to build conditional filters.
In the example below, users are filtered to those that are active and further filtered to jkratz
but only if the variable jamieOnly
is true
.
Note, to clear any any previous filters, use the where
method. This method starts a filter chain over again.
Custom Filters
Custom filters are supported on data tables using the filter
function. Use this boolean method with a delegate to determine whether a given row should be included in the filter.
In the example below, the filter returns users that are active or not mchermela
.
Group By
Group by is implicit. Adding columns to a select automatically groups any aggregates by those columns.
The example below totals Sales
by Product
.
Order By
Ordering and returning top N rows can be achieved as illustrated below.
The following example filters to active users and orders the rows by FullName
.
Sorting using orderBy
defaults to ascending order. To sort descending, set the second parameter to true
.
To filter the top N rows, use the top
method.
For more on data table filters, visit the DataTables reference page.
Last updated