Skip to content

Commit f9c9dff

Browse files
committed
refactor(igx-grid): Cleaned up some method params
Added docs
1 parent e99e7ce commit f9c9dff

File tree

5 files changed

+71
-19
lines changed

5 files changed

+71
-19
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.component.ts

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
15421542
public onRowDragEnd = new EventEmitter<IRowDragEndEventArgs>();
15431543

15441544
/**
1545-
* TODO: Write doc
1545+
* Emitted when a copy operation is executed.
1546+
* Fired only if copy behavior is enabled through the [`clipboardOptions`]{@link IgxGridBaseComponent#clipboardOptions}.
15461547
*/
15471548
@Output()
15481549
onGridCopy = new EventEmitter<IGridClipboardEvent>();
@@ -2326,13 +2327,25 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
23262327
}
23272328

23282329
/**
2329-
* TODO: Write doc
2330+
* Controls the copy behavior of the grid.
23302331
*/
23312332
@Input()
23322333
clipboardOptions = {
2334+
/**
2335+
* Enables/disables the copy behavior
2336+
*/
23332337
enabled: true,
2338+
/**
2339+
* Include the columns headers in the clipboard output.
2340+
*/
23342341
copyHeaders: true,
2342+
/**
2343+
* Apply the columns formatters (if any) on the data in the clipboard output.
2344+
*/
23352345
copyFormatters: true,
2346+
/**
2347+
* The separator used for formatting the copy output. Defaults to `\t`.
2348+
*/
23362349
separator: '\t'
23372350
};
23382351

@@ -2355,7 +2368,10 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
23552368

23562369
/* End of toolbar related definitions */
23572370

2358-
// TODO: Document
2371+
/**
2372+
* Emitted when making a range selection either through
2373+
* drag selection or through keyboard selection.
2374+
*/
23592375
@Output()
23602376
onRangeSelection = new EventEmitter<GridSelectionRange>();
23612377

@@ -4814,8 +4830,9 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
48144830
return this.selectionService.ranges;
48154831
}
48164832

4817-
extractDataFromSelection(source: any[], applyColumnFormatters = false): any[] {
4818-
let column: IgxColumnComponent;
4833+
4834+
protected extractDataFromSelection(source: any[], formatters = false, headers = false): any[] {
4835+
let columnsArray: IgxColumnComponent[];
48194836
let record = {};
48204837
const selectedData = [];
48214838

@@ -4833,11 +4850,14 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
48334850
}
48344851
const temp = Array.from(set);
48354852
for (const each of temp) {
4836-
column = visibleColumns[each];
4837-
if (column) {
4838-
record[column.field] = applyColumnFormatters && column.formatter ? column.formatter(source[row][column.field])
4839-
: source[row][column.field];
4840-
}
4853+
columnsArray = this.getSelectableColumnsAt(each);
4854+
columnsArray.forEach((col) => {
4855+
if (col) {
4856+
const key = headers ? col.header || col.field : col.field;
4857+
record[key] = formatters && col.formatter ? col.formatter(source[row][col.field])
4858+
: source[row][col.field];
4859+
}
4860+
});
48414861
}
48424862
if (Object.keys(record).length) {
48434863
selectedData.push(record);
@@ -4847,9 +4867,30 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
48474867
return selectedData;
48484868
}
48494869

4850-
getSelectedData(applyColumnFormatters = false) {
4870+
protected getSelectableColumnsAt(index) {
4871+
if (this.hasColumnLayouts) {
4872+
const visibleLayoutColumns = this.visibleColumns
4873+
.filter(col => col.columnLayout)
4874+
.sort((a, b) => a.visibleIndex - b.visibleIndex);
4875+
const colLayout = visibleLayoutColumns[index];
4876+
return colLayout ? colLayout.children.toArray() : [];
4877+
} else {
4878+
const visibleColumns = this.visibleColumns
4879+
.filter(col => !col.columnGroup)
4880+
.sort((a, b) => a.visibleIndex - b.visibleIndex);
4881+
return [ visibleColumns[index] ];
4882+
}
4883+
}
4884+
4885+
/**
4886+
*
4887+
* Returns an array of the current cell selection in the form of `[{ column.field: cell.value }, ...]`.
4888+
* If `formatters` is enabled, the cell value will be formatted by its respective column formatter (if any).
4889+
* If `headers` is enabled, it will use the column header (if any) instead of the column field.
4890+
*/
4891+
getSelectedData(formatters = false, headers = false) {
48514892
const source = this.verticalScrollContainer.igxForOf;
4852-
return this.extractDataFromSelection(source, applyColumnFormatters);
4893+
return this.extractDataFromSelection(source, formatters, headers);
48534894
}
48544895

48554896
/**
@@ -4895,7 +4936,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
48954936
return;
48964937
}
48974938

4898-
const data = this.getSelectedData(this.clipboardOptions.copyFormatters);
4939+
const data = this.getSelectedData(this.clipboardOptions.copyFormatters, this.clipboardOptions.copyHeaders);
48994940
const ev = { data, cancel: false } as IGridClipboardEvent;
49004941
this.onGridCopy.emit(ev);
49014942

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,10 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
933933
}
934934
}
935935

936-
getSelectedData(applyColumnFormatters = false): any[] {
936+
/**
937+
* @inheritdoc
938+
*/
939+
getSelectedData(formatters = false, headers = false): any[] {
937940
if (this.groupingExpressions.length) {
938941
const source = [];
939942

@@ -947,9 +950,9 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
947950
};
948951

949952
this.verticalScrollContainer.igxForOf.forEach(process);
950-
return this.extractDataFromSelection(source, applyColumnFormatters);
953+
return this.extractDataFromSelection(source, formatters, headers);
951954
} else {
952-
return super.getSelectedData(applyColumnFormatters);
955+
return super.getSelectedData(formatters, headers);
953956
}
954957
}
955958

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,10 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent implements IGridD
729729
};
730730
}
731731

732-
getSelectedData(applyColumnFormatters = false): any[] {
732+
/**
733+
* @inheritdoc
734+
*/
735+
getSelectedData(formatters = false, headers = false): any[] {
733736
const source = [];
734737

735738
const process = (record) => {
@@ -741,7 +744,7 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent implements IGridD
741744
};
742745

743746
this.verticalScrollContainer.igxForOf.forEach(process);
744-
return this.extractDataFromSelection(source, applyColumnFormatters);
747+
return this.extractDataFromSelection(source, formatters, headers);
745748
}
746749

747750
/**

src/app/grid-clipboard/grid-clipboard.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<div style="width: 50wh; height: 50vh">
2626
<igx-grid #grid [data]="data" primaryKey="ID"
2727
rowEditable="true"
28-
(onColumnInit)="$event.formatter = formatter"
28+
(onColumnInit)="initColumn($event)"
2929
[clipboardOptions]="options"
3030
[autoGenerate]="true">
3131
</igx-grid>

src/app/grid-clipboard/grid-clipboard.sample.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ export class GridClipboardSampleComponent {
2121
}
2222

2323
formatter = (value: any) => `** ${value} **`;
24+
25+
initColumn(column) {
26+
column.formatter = this.formatter;
27+
column.header = `🐱‍👤 ${column.field} 🐱‍🏍`;
28+
}
2429
}

0 commit comments

Comments
 (0)