Skip to content

Commit

Permalink
Add export button
Browse files Browse the repository at this point in the history
  • Loading branch information
JiashuHarryHuang committed Feb 3, 2024
1 parent 02d70ac commit e238d24
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion components/table/event-table/EventTableImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const EventTableImpl = ({
showPopup={showPopup}
setShowPopupTag={setShowPopupTag}
showPopupTag={showPopup}
handleExport={handleExport}
/>
<TableContainer>
<div id="table-container">
Expand Down
5 changes: 2 additions & 3 deletions components/table/event-table/TableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import { SearchContainter, TableButton } from '@/styles/table.styles';
import React from 'react';
import Image from 'next/image';
import { Button } from 'antd';
import { handleExport } from '@/utils/utils';

const TableHeader = ({
setShowPopup,
showPopup,
setShowPopupTag,
showPopupTag,
handleExport,
}: {
setShowPopup: (a: boolean) => void;
showPopup: boolean;
setShowPopupTag: (a: boolean) => void;
showPopupTag: boolean;
handleExport: () => void;
}) => {
return (
<>
Expand Down Expand Up @@ -43,7 +42,7 @@ const TableHeader = ({
/>
</TableButton>
<Button
onClick={handleExport}
onClick={() => handleExport('events')}
style={{
width: 250,
marginLeft: 90,
Expand Down
12 changes: 12 additions & 0 deletions components/table/program-table/TableHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { SearchContainter, TableButton } from '@/styles/table.styles';
import React from 'react';
import Image from 'next/image';
import { Button } from 'antd';
import { handleExport } from '@/utils/utils';

const TableHeader = ({
setShowPopUp,
Expand All @@ -21,6 +23,16 @@ const TableHeader = ({
style={{ marginLeft: 150 }}
/>
</TableButton>
<Button
onClick={() => handleExport('programs')}
style={{
width: 250,
marginLeft: 90,
backgroundColor: 'darkgray',
color: 'whitesmoke',
}}>
Export
</Button>
</SearchContainter>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const fetchData = async (route: string) => {
export const fetcher = (url: string) => fetch(url).then(res => res.json());

// function to export what is on the table at the time to an excel file
export const handleExport = () => {
export const handleExport = (fileName: string) => {
const workbook = XLSX.utils.table_to_book(
document.querySelector('#table-container')
);
Expand All @@ -54,5 +54,5 @@ export const handleExport = () => {
const blob = new Blob([excelBuffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
saveAs(blob, 'events.xlsx');
saveAs(blob, fileName + '.xlsx');
};

0 comments on commit e238d24

Please sign in to comment.