This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
import { Dropdown } from "react-bootstrap";
|
import { Dropdown } from "react-bootstrap";
|
||||||
import { Download } from "react-bootstrap-icons";
|
import { Download } from "react-bootstrap-icons";
|
||||||
|
|
||||||
@@ -7,16 +7,24 @@ const Export = ({ columns, data, filename = "export", customActions = [], show,
|
|||||||
const [exportColumns, setExportColumns] = useState(
|
const [exportColumns, setExportColumns] = useState(
|
||||||
columns.map(col => ({ ...col, show: true }))
|
columns.map(col => ({ ...col, show: true }))
|
||||||
);
|
);
|
||||||
|
const scrollContainerRef = useRef(null);
|
||||||
|
const scrollTopRef = useRef(0);
|
||||||
|
|
||||||
// Use external control if provided, otherwise use internal state
|
// Use external control if provided, otherwise use internal state
|
||||||
const showExportDropdown = show !== undefined ? show : internalShow;
|
const showExportDropdown = show !== undefined ? show : internalShow;
|
||||||
const handleToggle = onToggle || ((isOpen) => setInternalShow(isOpen));
|
const handleToggle = onToggle || ((isOpen) => setInternalShow(isOpen));
|
||||||
|
|
||||||
const handleColumnToggle = (columnKey) => {
|
const handleColumnToggle = (columnKey) => {
|
||||||
|
scrollTopRef.current = scrollContainerRef.current?.scrollTop || 0;
|
||||||
const updatedColumns = exportColumns.map(col =>
|
const updatedColumns = exportColumns.map(col =>
|
||||||
col.key === columnKey ? { ...col, show: !col.show } : col
|
col.key === columnKey ? { ...col, show: !col.show } : col
|
||||||
);
|
);
|
||||||
setExportColumns(updatedColumns);
|
setExportColumns(updatedColumns);
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (scrollContainerRef.current) {
|
||||||
|
scrollContainerRef.current.scrollTop = scrollTopRef.current;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
@@ -136,7 +144,7 @@ const Export = ({ columns, data, filename = "export", customActions = [], show,
|
|||||||
<hr style={{ margin: '8px 0', borderColor: '#ddd' }} />
|
<hr style={{ margin: '8px 0', borderColor: '#ddd' }} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div style={{ maxHeight: '200px', overflowY: 'auto', marginBottom: '15px' }}>
|
<div style={{ maxHeight: '200px', overflowY: 'auto', marginBottom: '15px' }} ref={scrollContainerRef}>
|
||||||
<h6 style={{ fontSize: '14px', marginBottom: '10px' }}>Select Columns:</h6>
|
<h6 style={{ fontSize: '14px', marginBottom: '10px' }}>Select Columns:</h6>
|
||||||
{exportColumns.map((column) => (
|
{exportColumns.map((column) => (
|
||||||
<div key={column.key} style={{ marginBottom: '8px' }}>
|
<div key={column.key} style={{ marginBottom: '8px' }}>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
import { Dropdown } from "react-bootstrap";
|
import { Dropdown } from "react-bootstrap";
|
||||||
import { Columns } from "react-bootstrap-icons";
|
import { Columns } from "react-bootstrap-icons";
|
||||||
|
|
||||||
const ManageTable = ({ columns, onColumnsChange, show, onToggle }) => {
|
const ManageTable = ({ columns, onColumnsChange, show, onToggle }) => {
|
||||||
const [internalShow, setInternalShow] = useState(false);
|
const [internalShow, setInternalShow] = useState(false);
|
||||||
const [tempColumns, setTempColumns] = useState(columns);
|
const [tempColumns, setTempColumns] = useState(columns);
|
||||||
|
const scrollContainerRef = useRef(null);
|
||||||
|
const scrollTopRef = useRef(0);
|
||||||
|
|
||||||
// Use external control if provided, otherwise use internal state
|
// Use external control if provided, otherwise use internal state
|
||||||
const showManageTableDropdown = show !== undefined ? show : internalShow;
|
const showManageTableDropdown = show !== undefined ? show : internalShow;
|
||||||
@@ -15,10 +17,16 @@ const ManageTable = ({ columns, onColumnsChange, show, onToggle }) => {
|
|||||||
}, [columns]);
|
}, [columns]);
|
||||||
|
|
||||||
const handleColumnToggle = (columnKey) => {
|
const handleColumnToggle = (columnKey) => {
|
||||||
|
scrollTopRef.current = scrollContainerRef.current?.scrollTop || 0;
|
||||||
const updatedColumns = tempColumns.map(col =>
|
const updatedColumns = tempColumns.map(col =>
|
||||||
col.key === columnKey ? { ...col, show: !col.show } : col
|
col.key === columnKey ? { ...col, show: !col.show } : col
|
||||||
);
|
);
|
||||||
setTempColumns(updatedColumns);
|
setTempColumns(updatedColumns);
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (scrollContainerRef.current) {
|
||||||
|
scrollContainerRef.current.scrollTop = scrollTopRef.current;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDone = () => {
|
const handleDone = () => {
|
||||||
@@ -51,7 +59,7 @@ const ManageTable = ({ columns, onColumnsChange, show, onToggle }) => {
|
|||||||
<h6>Manage Table Columns</h6>
|
<h6>Manage Table Columns</h6>
|
||||||
<div className="app-main-content-fields-section margin-sm dropdown-container">
|
<div className="app-main-content-fields-section margin-sm dropdown-container">
|
||||||
<div className="manage-table-columns-wrapper">
|
<div className="manage-table-columns-wrapper">
|
||||||
<div className="manage-table-columns-scroll">
|
<div className="manage-table-columns-scroll" ref={scrollContainerRef}>
|
||||||
{tempColumns.map((column) => (
|
{tempColumns.map((column) => (
|
||||||
<div key={column.key} style={{ marginBottom: '8px' }}>
|
<div key={column.key} style={{ marginBottom: '8px' }}>
|
||||||
<input
|
<input
|
||||||
|
|||||||
Reference in New Issue
Block a user