Skip to content

Commit

Permalink
fix when disableRowSelectionOnClick is not applied
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Mar 7, 2024
1 parent 6f8af5b commit 7276569
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ export const useGridCellSelection = (
cellData = serializeCellValue(cellParams, {
delimiterCharacter: clipboardCopyCellDelimiter,
ignoreValueFormatter,
shouldAppendQuotes: true,
});
} else {
cellData = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const useGridClipboard = (
includeHeaders: false,
// TODO: make it configurable
delimiter: clipboardCopyCellDelimiter,
shouldAppendQuotes: false,
});
} else {
const focusedCell = gridFocusCellSelector(apiRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const serializeCellValue = (
options: {
delimiterCharacter: string;
ignoreValueFormatter: boolean;
shouldAppendQuotes?: boolean;
shouldAppendQuotes: boolean;
},
) => {
const { delimiterCharacter, ignoreValueFormatter, shouldAppendQuotes = true } = options;
const { delimiterCharacter, ignoreValueFormatter, shouldAppendQuotes } = options;
let value: any;
if (ignoreValueFormatter) {
const columnType = cellParams.colDef.type;
Expand Down Expand Up @@ -57,6 +57,7 @@ const objectFormattedValueWarning = buildWarning([
type CSVRowOptions = {
delimiterCharacter: string;
sanitizeCellValue?: (value: any, delimiterCharacter: string, shouldAppendQuotes: boolean) => any;
shouldAppendQuotes: boolean;
};
class CSVRow {
options: CSVRowOptions;
Expand All @@ -79,7 +80,7 @@ class CSVRow {
this.rowString += this.options.sanitizeCellValue(
value,
this.options.delimiterCharacter,
true,
this.options.shouldAppendQuotes,
);
} else {
this.rowString += value;
Expand All @@ -98,14 +99,16 @@ const serializeRow = ({
getCellParams,
delimiterCharacter,
ignoreValueFormatter,
shouldAppendQuotes,
}: {
id: GridRowId;
columns: GridStateColDef[];
getCellParams: (id: GridRowId, field: string) => GridCellParams;
delimiterCharacter: string;
ignoreValueFormatter: boolean;
shouldAppendQuotes: boolean;
}) => {
const row = new CSVRow({ delimiterCharacter });
const row = new CSVRow({ delimiterCharacter, shouldAppendQuotes });

columns.forEach((column) => {
const cellParams = getCellParams(id, column.field);
Expand All @@ -114,7 +117,7 @@ const serializeRow = ({
objectFormattedValueWarning();
}
}
row.addValue(serializeCellValue(cellParams, { delimiterCharacter, ignoreValueFormatter }));
row.addValue(serializeCellValue(cellParams, { delimiterCharacter, ignoreValueFormatter , shouldAppendQuotes}));
});

return row.getRowString();
Expand All @@ -128,6 +131,7 @@ interface BuildCSVOptions {
includeColumnGroupsHeaders: NonNullable<GridCsvExportOptions['includeColumnGroupsHeaders']>;
ignoreValueFormatter: boolean;
apiRef: React.MutableRefObject<GridApiCommunity>;
shouldAppendQuotes: boolean;
}

export function buildCSV(options: BuildCSVOptions): string {
Expand All @@ -139,6 +143,7 @@ export function buildCSV(options: BuildCSVOptions): string {
includeColumnGroupsHeaders,
ignoreValueFormatter,
apiRef,
shouldAppendQuotes,
} = options;

const CSVBody = rowIds
Expand All @@ -150,6 +155,7 @@ export function buildCSV(options: BuildCSVOptions): string {
getCellParams: apiRef.current.getCellParams,
delimiterCharacter,
ignoreValueFormatter,
shouldAppendQuotes,
})}\r\n`,
'',
)
Expand Down Expand Up @@ -179,7 +185,11 @@ export function buildCSV(options: BuildCSVOptions): string {
}, {});

for (let i = 0; i < maxColumnGroupsDepth; i += 1) {
const headerGroupRow = new CSVRow({ delimiterCharacter, sanitizeCellValue });
const headerGroupRow = new CSVRow({
delimiterCharacter,
sanitizeCellValue,
shouldAppendQuotes,
});
headerRows.push(headerGroupRow);
filteredColumns.forEach((column) => {
const columnGroupId = (columnGroupPathsLookup[column.field] || [])[i];
Expand All @@ -189,7 +199,7 @@ export function buildCSV(options: BuildCSVOptions): string {
}
}

const mainHeaderRow = new CSVRow({ delimiterCharacter, sanitizeCellValue });
const mainHeaderRow = new CSVRow({ delimiterCharacter, sanitizeCellValue, shouldAppendQuotes });
filteredColumns.forEach((column) => {
mainHeaderRow.addValue(column.headerName || column.field);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const useGridCsvExport = (
includeColumnGroupsHeaders: options.includeColumnGroupsHeaders ?? true,
ignoreValueFormatter,
apiRef,
shouldAppendQuotes: options.shouldAppendQuotes ?? true,
});
},
[logger, apiRef, ignoreValueFormatter],
Expand Down
6 changes: 6 additions & 0 deletions packages/x-data-grid/src/models/gridExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export interface GridCsvExportOptions extends GridFileExportOptions {
* @returns {GridRowId[]} The list of row ids to export.
*/
getRowsToExport?: (params: GridCsvGetRowsToExportParams) => GridRowId[];
/**
* If `false`, the quotes will not be appended to the cell value.
* @internal
* @default true
*/
shouldAppendQuotes?: boolean;
}

/**
Expand Down

0 comments on commit 7276569

Please sign in to comment.