Skip to content
Closed
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
9 changes: 8 additions & 1 deletion addon/-private/column-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { computed } from '@ember/object';
import { gt, readOnly } from '@ember/object/computed';

import { scheduler, Token } from 'ember-raf-scheduler';
import { SUPPORTS_CLOSURE_ACTIONS } from 'ember-compatibility-helpers';

import { getOrCreate } from './meta-cache';
import { objectAt, move, splice } from './utils/array';
Expand Down Expand Up @@ -860,7 +861,13 @@ export default EmberObject.extend({

this.container.classList.remove('is-reordering');

this.sendAction('onReorder', get(node, 'column'), get(closestColumn, 'column'));
if (SUPPORTS_CLOSURE_ACTIONS) {
if (typeof this.onReorder === 'function') {
this.onReorder(get(node, 'column'), get(closestColumn, 'column'));
}
} else {
this.sendAction('onReorder', get(node, 'column'), get(closestColumn, 'column'));
}
},

startResize(node, clientX) {
Expand Down
1 change: 1 addition & 0 deletions addon/components/ember-thead/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export default Component.extend({
this.columnMetaCache = new Map();

this.columnTree = ColumnTree.create({
onReorder: typeof this.onReorder === 'function' ? this.onReorder.bind(this) : null,
sendAction: this.sendAction.bind(this),
columnMetaCache: this.columnMetaCache,
containerWidthAdjustment: this.containerWidthAdjustment,
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/generate-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const fullTable = hbs`


onUpdateSorts="onUpdateSorts"
onReorder="onReorder"
onReorder=(if supportsClosureActions onReorder "onReorder")
onResize="onResize"

as |h|
Expand Down
16 changes: 11 additions & 5 deletions tests/integration/components/headers/reorder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getScale } from 'ember-table/test-support/helpers/element';
import TablePage from 'ember-table/test-support/pages/ember-table';
import { toBase26 } from 'dummy/utils/base-26';

import { SUPPORTS_CLOSURE_ACTIONS } from 'ember-compatibility-helpers';

const table = new TablePage();

export async function scrollToEdge(targetElement, edgeOffset, direction) {
Expand Down Expand Up @@ -58,13 +60,17 @@ module('Integration | headers | reorder', function() {
assert.equal(table.headers.objectAt(0).text.trim(), 'A', 'First column is swapped forward');
});

test('column reorder action is sent up to controller', async function(assert) {
this.on('onReorder', function(insertedColumn, insertedAfter) {
test('calls the closure action onReorder or sendAction given the ember version', async function(assert) {
let onReorder = function(insertedColumn, insertedAfter) {
assert.equal(insertedColumn.name, 'A', 'old column index is correct');
assert.equal(insertedAfter.name, 'B', 'new column index is correct');
});

await generateTable(this);
};
if (SUPPORTS_CLOSURE_ACTIONS) {
await generateTable(this, { onReorder, supportsClosureActions: SUPPORTS_CLOSURE_ACTIONS });
} else {
this.on('onReorder', onReorder);
await generateTable(this);
}
await table.headers.objectAt(0).reorderBy(1);
});

Expand Down