Comments (3)
Can we push this @MBilalShafi ? It seems a customer has some need for this.
from mui-x.
Hey @roccodev92, the clipboard copy indeed doesn't consider the columns sorted row values for the selected cells which could be fixed by doing the following changes to the cell selection plugin, clipboard paste seems to work fine though.
diff --git a/packages/x-data-grid-premium/src/hooks/features/cellSelection/useGridCellSelection.ts b/packages/x-data-grid-premium/src/hooks/features/cellSelection/useGridCellSelection.ts
index 5877bfe51..8675b83b1 100644
--- a/packages/x-data-grid-premium/src/hooks/features/cellSelection/useGridCellSelection.ts
+++ b/packages/x-data-grid-premium/src/hooks/features/cellSelection/useGridCellSelection.ts
@@ -23,6 +23,8 @@ import {
gridFocusCellSelector,
GridCellParams,
GRID_REORDER_COL_DEF,
+ useGridSelector,
+ gridSortedRowIdsSelector,
} from '@mui/x-data-grid-pro';
import { gridCellSelectionStateSelector } from './gridCellSelectionSelector';
import { GridCellSelectionApi } from './gridCellSelectionInterfaces';
@@ -61,6 +63,7 @@ export const useGridCellSelection = (
const lastMouseDownCell = React.useRef<GridCellCoordinates | null>();
const mousePosition = React.useRef<{ x: number; y: number } | null>(null);
const autoScrollRAF = React.useRef<number | null>();
+ const sortedRowIds = useGridSelector(apiRef, gridSortedRowIdsSelector);
const ignoreValueFormatterProp = props.ignoreValueFormatterDuringExport;
const ignoreValueFormatter =
@@ -547,7 +550,9 @@ export const useGridCellSelection = (
return value;
}
const cellSelectionModel = apiRef.current.getCellSelectionModel();
- const copyData = Object.keys(cellSelectionModel).reduce((acc, rowId) => {
+ const unsortedSelectedRowIds = Object.keys(cellSelectionModel);
+ const sortedSelectedRowIds = sortedRowIds.filter((id) => unsortedSelectedRowIds.includes(`${id}`));
+ const copyData = sortedSelectedRowIds.reduce<string>((acc, rowId) => {
const fieldsMap = cellSelectionModel[rowId];
const rowString = Object.keys(fieldsMap).reduce((acc2, field) => {
let cellData: string;
@@ -566,7 +571,7 @@ export const useGridCellSelection = (
}, '');
return copyData;
},
- [apiRef, ignoreValueFormatter, clipboardCopyCellDelimiter],
+ [apiRef, ignoreValueFormatter, clipboardCopyCellDelimiter, sortedRowIds],
);
useGridRegisterPipeProcessor(apiRef, 'isCellSelected', checkIfCellIsSelected);
@cherniavskii If it was intentionally set like this for some reason during the clipboard feature development, please let me know, otherwise we can fix the issue by doing a change similar to the above diff.
from mui-x.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.
How did we do @roccodev92?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.
from mui-x.
Related Issues (20)
- [charts] `onMarkClick` not working HOT 5
- [question] Can you help me adding code for the ticket https://github.com/mui/mui-x/issues/13298 HOT 2
- [data grid] Shift + Arrow Keys Not Selecting Correct Rows After Independent Row Selection HOT 2
- [charts][docs] The AxisConfig API page is wrong
- [data grid] re-rendering / resetting filter on state change HOT 9
- [data grid] How to get the total row count including children rows HOT 5
- [data grid] Page row count to be set on child rows when row grouping is applied HOT 2
- & .MuiDataGrid-columnHeaders is not working with @mui/x-data-grid-pro": ^7.1.1 HOT 1
- [charts] How to add min and max scaling on axis for bar charts to remove decimal scale values HOT 3
- [data grid] changing data is slow HOT 2
- [question] How can i remove column sorting from datagridView ? (^6.19.6)
- MUI Datagrid sortComparator function signature is not available when using typescript
- [data grid] Row spanning with tree/grouping behavior HOT 1
- [charts] Pie chart overflow with legend HOT 5
- [data grid]: there is an issue with the design on the right side when dragging
- [data grid] `processRowUpdate` does not get fired when grid is styled using `styled` from `@mui/material/styles` HOT 4
- [charts] types not exported from ChartsTooltipTable HOT 7
- Leap year data grid date column filter cant be filled from left to right HOT 3
- [charts] Improve docs about how to pick the correct scaleType HOT 7
- [charts] Tooltips for points on the edge of the chart are not always shown with tooltip trigger item HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.