Skip to content

Commit 0727b3e

Browse files
Merge pull request #694 from sudhanshutech/column/visibililty
Add column visibility responsive handler and add default options in table
2 parents 47ac900 + 0827b88 commit 0727b3e

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ColView, updateVisibleColumns } from './responsive-column';
2+
3+
export { updateVisibleColumns };
4+
export type { ColView };
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// colViews screen size reference
2+
/*
3+
na: Not visible at any screen width
4+
xs: width < 585,
5+
s: width > 585 && width < 690,
6+
m: width > 690 && width < 775,
7+
l: width > 775 && width < 915,
8+
xl: width > 915 && width < 1140
9+
All columns except "na" are visible for width > 1140
10+
*/
11+
12+
export interface ColView {
13+
0: string; // column name
14+
1: 'na' | 'xs' | 's' | 'm' | 'l' | 'xl'; // screen size
15+
}
16+
17+
export const updateVisibleColumns = (
18+
colViews: ColView[],
19+
width: number
20+
): Record<string, boolean> => {
21+
// showCols object contains key value pairs that represent whether a column is visible or hidden.
22+
// i.e, Here, key = column name, and value = true/false where true means visible and false means hidden
23+
const showCols: Record<string, boolean> = {};
24+
25+
// colViews is a 2D array where each element is an array of 2 elements namely,
26+
// column name and the screen size till which they are visible
27+
colViews.forEach((col) => {
28+
// Hide the columns for any screen size
29+
if (col[1] === 'na') {
30+
showCols[col[0]] = false;
31+
} else if (width > 1140) {
32+
// Display all columns above width 1140
33+
showCols[col[0]] = true;
34+
} else if (width >= 915 && width < 1140) {
35+
if (['xs', 's', 'm', 'l', 'xl'].includes(col[1])) {
36+
showCols[col[0]] = true;
37+
} else {
38+
showCols[col[0]] = false;
39+
}
40+
} else if (width >= 775 && width < 915) {
41+
if (['xs', 's', 'm', 'l'].includes(col[1])) {
42+
showCols[col[0]] = true;
43+
} else {
44+
showCols[col[0]] = false;
45+
}
46+
} else if (width >= 690 && width < 775) {
47+
if (['xs', 's', 'm'].includes(col[1])) {
48+
showCols[col[0]] = true;
49+
} else {
50+
showCols[col[0]] = false;
51+
}
52+
} else if (width >= 585 && width < 690) {
53+
if (['xs', 's'].includes(col[1])) {
54+
showCols[col[0]] = true;
55+
} else {
56+
showCols[col[0]] = false;
57+
}
58+
} else if (width < 585) {
59+
if (col[1] === 'xs') {
60+
showCols[col[0]] = true;
61+
} else {
62+
showCols[col[0]] = false;
63+
}
64+
}
65+
});
66+
67+
return showCols;
68+
};

src/custom/ResponsiveDataTable.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ const ResponsiveDataTable = ({
170170

171171
const updatedOptions = {
172172
...options,
173+
print: false,
174+
download: false,
175+
search: false,
176+
filter: false,
177+
viewColumns: false,
173178
rowsPerPageOptions: rowsPerPageOptions,
174179
onViewColumnsChange: (column: string, action: string) => {
175180
switch (action) {

src/custom/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { FeedbackButton } from './Feedback';
2828
import { FlipCard, FlipCardProps } from './FlipCard';
2929
import { useWindowDimensions } from './Helpers/Dimension';
3030
import { useNotificationHandler } from './Helpers/Notification';
31+
import { ColView, updateVisibleColumns } from './Helpers/ResponsiveColumns/responsive-coulmns.tsx';
3132
import { LearningCard } from './LearningCard';
3233
import { RenderMarkdown } from './Markdown';
3334
import { ModalCard } from './ModalCard';
@@ -73,6 +74,7 @@ export {
7374
StyledDialogTitle,
7475
TransferList,
7576
UniversalFilter,
77+
updateVisibleColumns,
7678
useNotificationHandler,
7779
useWindowDimensions,
7880
withErrorBoundary,
@@ -101,6 +103,7 @@ export { CustomizedStepper, useStepper } from './Stepper';
101103

102104
export type {
103105
CatalogFilterProps,
106+
ColView,
104107
CustomColumn,
105108
CustomColumnVisibilityControlProps,
106109
CustomDialogProps,

0 commit comments

Comments
 (0)