diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.html b/lib/core/src/lib/datatable/components/datatable/datatable.component.html index a3069b2874c..a97c6427796 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.html +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.html @@ -10,7 +10,7 @@ { describe('Header modes', () => { const newData = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]); const emptyData = new ObjectDataTableAdapter(); + const getDropList = (): CdkDropList => { + dataTable.showHeader = ShowHeaderMode.Data; + dataTable.loading = false; + dataTable.data = newData; + fixture.detectChanges(); + return fixture.debugElement.query(By.directive(CdkDropList)).injector.get(CdkDropList); + }; it('should show the header if showHeader is `Data` and there is data', () => { dataTable.showHeader = ShowHeaderMode.Data; @@ -285,6 +292,32 @@ describe('DataTable', () => { dataTable.loading = true; testNotShownHeader(emptyData); }); + + it('should have assigned filterDisabledColumns to sortPredicate of CdkDropList', () => { + expect(getDropList().sortPredicate).toBeDefined(); + }); + + it('should sortPredicate from CdkDropList return true if column is enabled', () => { + const dropList = getDropList(); + spyOn(dropList, 'getSortedItems').and.returnValue([{ + disabled: true + }, { + disabled: false + }] as CdkDrag[]); + + expect(dropList.sortPredicate(1, undefined, dropList)).toBeTrue(); + }); + + it('should sortPredicate from CdkDropList return false if column is disabled', () => { + const dropList = getDropList(); + spyOn(dropList, 'getSortedItems').and.returnValue([{ + disabled: true + }, { + disabled: true + }] as CdkDrag[]); + + expect(dropList.sortPredicate(1, undefined, dropList)).toBeFalse(); + }); }); it('should emit "sorting-changed" DOM event', (done) => { diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.ts b/lib/core/src/lib/datatable/components/datatable/datatable.component.ts index 391a60a9dc3..b76d6ec6858 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.ts +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.ts @@ -975,7 +975,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges, return `0 1 ${width < DataTableComponent.MINIMUM_COLUMN_SIZE ? DataTableComponent.MINIMUM_COLUMN_SIZE : width}px`; } - sortPredicate(index: number, _drag: CdkDrag, drop: CdkDropList): boolean { + filterDisabledColumns(index: number, _drag: CdkDrag, drop: CdkDropList): boolean { return !drop.getSortedItems()[index].disabled; }