Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,38 @@ import {
CellExternalCopyManagerExtension,
CheckboxSelectorExtension,
ColumnPickerExtension,
CurrentSorter,
DraggableGroupingExtension,
GridMenuExtension,
GridOption,
GroupItemMetaProviderExtension,
HeaderButtonExtension,
HeaderMenuExtension,
RowDetailViewExtension,
RowMoveManagerExtension,
RowSelectionExtension
RowSelectionExtension,
} from '..';
import { Subject } from 'rxjs';

const sharedServiceStub = {} as SharedService;
Object.defineProperty(sharedServiceStub, 'dataView', {
get: jest.fn(() => 'bar'),
set: jest.fn()
});

const sortServiceStub = {
attachLocalOnSort: jest.fn(),
dispose: jest.fn(),
loadLocalPresets: jest.fn(),
onSortChanged: new Subject<CurrentSorter[]>(),
onSortCleared: new Subject<boolean>()
};

// jest.mock('slickgrid/slick.dataview', () => ({
// Slick: {
// Data: mockDataView
// }
// }));

describe('App Component', () => {
let fixture: ComponentFixture<AngularSlickgridComponent>;
Expand All @@ -60,7 +83,6 @@ describe('App Component', () => {
GroupingAndColspanService,
ResizerService,
SharedService,
SortService,
TranslateService,
AutoTooltipExtension,
CellExternalCopyManagerExtension,
Expand All @@ -75,6 +97,7 @@ describe('App Component', () => {
RowMoveManagerExtension,
RowSelectionExtension,
SlickgridConfig,
{ provide: SortService, useValue: sortServiceStub },
],
imports: [
RouterTestingModule,
Expand Down Expand Up @@ -114,4 +137,53 @@ describe('App Component', () => {

expect(() => fixture.detectChanges()).toThrowError('[Angular-Slickgrid] requires a "grid-height" or the "enableAutoResize"');
});

describe('dataView options', () => {
let dataView;
let dataViewSpy;

it('should call the onDataviewCreated emitter', () => {
const spy = jest.spyOn(component.onDataviewCreated, 'emit');
fixture.detectChanges();
expect(spy).toHaveBeenCalled();
});

it('should call the "executeAfterDataviewCreated" and "loadLocalPresets" methods and Sorter Presets are provided in the Grid Options', () => {
const compSpy = jest.spyOn(component, 'executeAfterDataviewCreated');
const sortSpy = jest.spyOn(sortServiceStub, 'loadLocalPresets');

component.gridOptions = { presets: { sorters: [{ columnId: 'field1', direction: 'DESC' }] } } as GridOption;
fixture.detectChanges();

expect(compSpy).toHaveBeenCalled();
expect(sortSpy).toHaveBeenCalled();
});

it('should call the DataView syncGridSelection method with 2nd argument as True when the "dataView" grid option is a boolean and is set to True', () => {
component.onDataviewCreated.subscribe((internalDataView) => {
dataView = internalDataView;
dataViewSpy = jest.spyOn(internalDataView, 'syncGridSelection');
});
component.gridOptions = { dataView: { syncGridSelection: true }, enableRowSelection: true } as GridOption;
fixture.detectChanges();

expect(dataView).toBeTruthy();
expect(dataViewSpy).toHaveBeenCalledWith(component.grid, true);
});

it('should call the DataView syncGridSelection method with 3 arguments when the "dataView" grid option is provided as an object', () => {
component.onDataviewCreated.subscribe((internalDataView) => {
dataView = internalDataView;
dataViewSpy = jest.spyOn(internalDataView, 'syncGridSelection');
});
component.gridOptions = {
dataView: { syncGridSelection: { preserveHidden: true, preserveHiddenOnSelectionChange: false } },
enableRowSelection: true
} as GridOption;
fixture.detectChanges();

expect(dataView).toBeTruthy();
expect(dataViewSpy).toHaveBeenCalledWith(component.grid, true, false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn

destroy(emptyDomElementContainer = false) {
const gridContainerId = this.gridOptions && this.gridOptions.gridContainerId;
this.dataView = [];
this.dataView = undefined;
this.gridOptions = {};
this.extensionService.dispose();
this.filterService.dispose();
Expand Down Expand Up @@ -281,10 +281,15 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
this.dataView.setItems(this._dataset, this.gridOptions.datasetIdPropertyName);
this.dataView.endUpdate();

// if you don't want the items that are not visible (due to being filtered out
// or being on a different page) to stay selected, pass 'false' to the second arg
// if you don't want the items that are not visible (due to being filtered out or being on a different page)
// to stay selected, pass 'false' to the second arg
if (this.gridOptions && this.gridOptions.dataView && this.gridOptions.dataView.hasOwnProperty('syncGridSelection')) {
this.dataView.syncGridSelection(this.grid, this.gridOptions.dataView.syncGridSelection);
const syncGridSelection = this.gridOptions.dataView.syncGridSelection;
if (typeof syncGridSelection === 'boolean') {
this.dataView.syncGridSelection(this.grid, this.gridOptions.dataView.syncGridSelection);
} else {
this.dataView.syncGridSelection(this.grid, syncGridSelection.preserveHidden, syncGridSelection.preserveHiddenOnSelectionChange);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ export interface GridOption {
/** Unique property name on the dataset used by Slick.Data.DataView */
datasetIdPropertyName?: string;

/** Some of the SlickGrid DataView options */
dataView?: {
/**
* if you don't want the items that are not visible (due to being filtered out
* or being on a different page) to stay selected, the set this property as 'false'
* If you don't want the items that are not visible (due to being filtered out or being on a different page)
* to stay selected, the set this property as 'false'. You can also set any of the preserve options instead of a boolean value.
*/
syncGridSelection?: boolean;
syncGridSelection?: boolean | { preserveHidden: boolean; preserveHiddenOnSelectionChange: boolean; };
};

/** Default column width, is set to 80 when null */
Expand Down