Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 78: Support secondary sorting in defaultSorting #81

Merged
merged 3 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ If you want to add a table on your visualization:
- `onComplete:` _(function, default: null)_ Callback function when the table finished rendering.
- `className:` _(string, default: 'table table-striped table-bordered')_ Table class name
- `rowClassName:` _(function(d), default: null)_ Function that returns the row class name depending on its content. Useful to highlight rows.
- `defaultSorting:` _(object, default: see below)_ How we sort things on the table.
- `defaultSorting:` _(object or table or object, default: see below)_ How we sort things on the table. You can specify a an array of two objects for secondary sorting.
- `defaultSorting.key:` _(string, default: <first column shown>)_ default sorting on which column.
- `defaultSorting.mode:` _(string, default: 'asc')_ sorting mode: `asc` for ascending, `desc` for descending.
- `collapseRowsBy:` _([string, ...], default: null)_ Array of columns that we want to be collapsed.
Expand Down
9 changes: 6 additions & 3 deletions dist/maptable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/maptable.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/maptable.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ export default class Table {
.attr('id', d => `column_header_${utils.sanitizeKey(d.key)}`);

if (this.options.defaultSorting) {
this.sortColumn(this.options.defaultSorting.key, this.options.defaultSorting.mode);
} else {
this.render();
if (Array.isArray(this.options.defaultSorting) && this.options.defaultSorting.length === 2) {
this.sorting = this.options.defaultSorting;
} else {
this.sorting = [this.options.defaultSorting];
}
}
this.render();

// On complete
if (this.options.onComplete && this.options.onComplete.constructor === Function) {
Expand Down