Skip to content

Commit

Permalink
[ACS-6489] Add resizable option for column data model (#9220)
Browse files Browse the repository at this point in the history
* [ACS-6489] Add resizable option for column data model

* [ACS-6489] CR fixes
  • Loading branch information
MichalKinas authored Jan 25, 2024
1 parent 62bc842 commit 2c0ad71
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/core/components/data-column.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Defines column properties for DataTable, Tasklist, Document List and other compo
| cssClass | `string` | | Additional CSS class to be applied to column (header and cells). |
| customData | `any` | | You can specify any custom data which can be used by any specific feature |
| draggable | `boolean` | false | Enable drag and drop for header column |
| resizable | `boolean` | true | Enable column resizing |
| editable | `boolean` | false | Toggles the editing support of the column data. |
| focus | `boolean` | true | Enable or disable cell focus |
| format | `string` | | Value format (if supported by the parent component), for example format of the date. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</span>
</div>
<div
*ngIf="isResizingEnabled"
*ngIf="isResizingEnabled && col.resizable"
adf-resize-handle
class="adf-datatable__resize-handle"
[resizableContainer]="resizableElement">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,10 @@ describe('Column Resizing', () => {

const getResizeHandler = (): HTMLDivElement => fixture.debugElement.nativeElement.querySelector('.adf-datatable__resize-handle');

const getResizeHandlersCount = (): number => {
const resizeHandlers = fixture.debugElement.nativeElement.querySelectorAll('.adf-datatable__resize-handle');
return resizeHandlers.length;
};

const testClassesAfterResizing = (headerColumnsSelector = '.adf-datatable-cell-header', excludedClass = 'adf-datatable__cursor--pointer') => {
dataTable.isResizingEnabled = true;
Expand Down Expand Up @@ -1744,6 +1748,22 @@ describe('Column Resizing', () => {
});
});

it('should display resize handle for each column by default', () => {
dataTable.isResizingEnabled = true;
fixture.detectChanges();

expect(getResizeHandlersCount()).toBe(2);
});

it('should NOT display resize handle for the column when the column has resizable param set to false', () => {
dataTable.isResizingEnabled = true;
dataTableSchema[0].resizable = false;
dataTable.data = new ObjectDataTableAdapter([...data], [...dataTableSchema]);
fixture.detectChanges();

expect(getResizeHandlersCount()).toBe(1);
});

it('should display resize handle when the feature is Enabled [isResizingEnabled=true]', () => {
dataTable.isResizingEnabled = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ export default {
}
}
},
resizable: {
description: 'Toggles resize for column.',
control: { type: 'boolean' },
defaultValue: true,
table: {
category: 'Component Inputs',
type: {
summary: 'boolean'
},
defaultValue: {
summary: true
}
}
},
editable: {
description: 'Toggles the editing support of the column data.',
control: { type: 'boolean', disable: true },
Expand Down Expand Up @@ -328,8 +342,8 @@ const template: Story<DataColumnComponent> = (args: DataColumnComponent & { rows
template: `
<adf-datatable [rows]="rows">
<data-columns>
<data-column
[key]="key"
<data-column
[key]="key"
[type]="type"
[title]="title"
[editable]="editable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class DataColumnComponent implements OnInit {
@Input()
draggable: boolean = false;

/** Enable resize for column */
@Input()
resizable = true;

/** Hide column */
@Input()
isHidden: boolean = false;
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/lib/datatable/data/data-column.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface DataColumn<T = unknown> {
sortingKey?: string;
header?: TemplateRef<any>;
draggable?: boolean;
resizable?: boolean;
isHidden?: boolean;
width?: number;
customData?: T;
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/lib/datatable/data/object-datacolumn.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class ObjectDataColumn<T = unknown> implements DataColumn<T> {
sortingKey?: string;
header?: TemplateRef<any>;
draggable: boolean;
resizable: boolean;
isHidden: boolean;
customData?: T;
width?: number;
Expand All @@ -58,6 +59,7 @@ export class ObjectDataColumn<T = unknown> implements DataColumn<T> {
this.sortingKey = input.sortingKey;
this.header = input.header;
this.draggable = input.draggable ?? false;
this.resizable = input.resizable ?? true;
this.isHidden = input.isHidden ?? false;
this.customData = input.customData;
this.width = input.width;
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/lib/mock/data-column.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const getDataColumnMock = <T = unknown>(
sortingKey: 'sortingKey',
header: undefined,
draggable: false,
resizable: true,
isHidden: false,
customData: undefined,
...column
Expand Down
1 change: 1 addition & 0 deletions lib/extensions/src/lib/config/document-list.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export interface DocumentListPresetRef extends ExtensionElement {
visible?: string;
};
draggable?: boolean;
resizable?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@
"desktopOnly": {
"description": "Display column only for large screens",
"type": "boolean"
},
"resizable": {
"description": "Toggles resizable state of the column",
"type": "boolean"
}
}
}
Expand Down

0 comments on commit 2c0ad71

Please sign in to comment.