An indexed sorter Datasaur module.
The datasaur-simple-sort
data source provides a means to sort the original set of rows basec on the values in a given column.
datasaur-simple-sort
sits on top of an indexed datasource. For example:
var Source = require('datasaur-local'); // v3.0.0 or higher
var Indexer = require('datasaur-indexed'); // this version must be >= that of datasaur-local
var Sorter = require('datasaur-simple-sort'); // this version must be >= that of datasaur-indexed
var dataModel = new Sorter(new Indexer(new Source));
datasaur-simple-sort
defines a single custom shared property.
The version string from package.json. (This is a static property of the constructor.)
datasaur-simple-sort
defines a single custom instance method.
dataModel.sort(0); // alpha ascending by first column
The optional options
parameter may contain an object with the following properties, all of which are optional:
Name | Values |
---|---|
dir |
'DESC' (case-insensitive) reverses the sort. Any other value leaves the sort in ascending order. |
comparator |
A function to be bound to columnIndex with the data source (this.next ) as the calling context. This function is then passed to Array.prototype.sort |
This sorter fails for computed cells or columns because it calls this.getValue
directly instead of DatasaurIndexed.valOrFunc
.
That said, it is still useable on computed columns if sorting on the uncomputed values would produce acceptable results.
Array.prototype.sort
does not naturally perform a stable sort, meaning that the "sorted" order of rows with identical sort arguments is undefined.
Sorting by multiple columns, each of which may be ascending or descending, is somewhat more complicated,
essentially involving dynamically adding a Sorter
stage for each column to be sorted.
See datasaur-filter
which does something like that,
but forces Array.prototype.sort
to do a stable sort
(which is is not naturally inclined to do), and properly handles computed cells and columns.
Note: As of this writing datasaur-filter
has not yet been updated to v3.0.0.
Published as an npm module to npmjs.org to be npm installed:
npm install datasaur-simple-sort
Published as a Hypergrid Client Module to be loaded by the client with a <script>
tag:
<script src="https://fin-hypergrid.github.io/datasaur-simple-sort/3.0.0/build/datasaur-simple-sort.js"></script>
The above <script>
tag loads the module into fin.Hypergrid.modules['datasaur-simple-sort']
.
Once loaded it can be referenced from another Hypergrid client module with require(...)
:
var DatasaurSimpleSort = require('datasaur-simple-sort');
Or from some other script with fin.Hypergrid.require(...)
:
var DatasaurSimpleSort = fin.Hypergrid.require('datasaur-simple-sort');
3.0.1
- Sort on the unsorted data rather than the sorted data.
- Delete the index when
option.dir
is falsy.
3.0.0
— Initial commit.