mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
emit "sorting-changed" DOM event (DataTable) (#2916)
This commit is contained in:
committed by
Eugenio Romano
parent
2080d75d51
commit
0e51208333
@@ -172,6 +172,7 @@ These events bubble up the component tree and can be handled by any parent compo
|
|||||||
| row-select | Raised after user selects a row |
|
| row-select | Raised after user selects a row |
|
||||||
| row-unselect | Raised after user unselects a row |
|
| row-unselect | Raised after user unselects a row |
|
||||||
| row-keyup | Raised on the 'keyup' event for the focused row. |
|
| row-keyup | Raised on the 'keyup' event for the focused row. |
|
||||||
|
| sorting-changed | Raised after user clicks the sortable column header. |
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
|
@@ -51,6 +51,27 @@ describe('DataTable', () => {
|
|||||||
element = fixture.debugElement.nativeElement;
|
element = fixture.debugElement.nativeElement;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit "sorting-changed" DOM event', (done) => {
|
||||||
|
const column = new ObjectDataColumn({ key: 'name', sortable: true, direction: 'asc' });
|
||||||
|
dataTable.data = new ObjectDataTableAdapter(
|
||||||
|
[
|
||||||
|
{ name: '1' },
|
||||||
|
{ name: '2' }
|
||||||
|
],
|
||||||
|
[ column ]
|
||||||
|
);
|
||||||
|
dataTable.data.setSorting(new DataSorting('name', 'desc'));
|
||||||
|
|
||||||
|
fixture.nativeElement.addEventListener('sorting-changed', (event: CustomEvent) => {
|
||||||
|
expect(event.detail.key).toBe('name');
|
||||||
|
expect(event.detail.direction).toBe('asc');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
dataTable.ngOnChanges({});
|
||||||
|
dataTable.onColumnHeaderClick(column);
|
||||||
|
});
|
||||||
|
|
||||||
it('should change the rows on changing of the data', () => {
|
it('should change the rows on changing of the data', () => {
|
||||||
let newData = new ObjectDataTableAdapter(
|
let newData = new ObjectDataTableAdapter(
|
||||||
[
|
[
|
||||||
|
@@ -369,6 +369,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
|
|||||||
newDirection = current.direction === 'asc' ? 'desc' : 'asc';
|
newDirection = current.direction === 'asc' ? 'desc' : 'asc';
|
||||||
}
|
}
|
||||||
this.data.setSorting(new DataSorting(column.key, newDirection));
|
this.data.setSorting(new DataSorting(column.key, newDirection));
|
||||||
|
this.emitSortingChangedEvent(column.key, newDirection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,4 +520,15 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
|
|||||||
});
|
});
|
||||||
this.elementRef.nativeElement.dispatchEvent(domEvent);
|
this.elementRef.nativeElement.dispatchEvent(domEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private emitSortingChangedEvent(key: string, direction: string) {
|
||||||
|
const domEvent = new CustomEvent('sorting-changed', {
|
||||||
|
detail: {
|
||||||
|
key,
|
||||||
|
direction
|
||||||
|
},
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
|
this.elementRef.nativeElement.dispatchEvent(domEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user