@@ -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
0 commit comments