import
"./App.css"
;
import * as React from
"react"
;
import Table from
"@mui/material/Table"
;
import TableBody from
"@mui/material/TableBody"
;
import TableCell from
"@mui/material/TableCell"
;
import TableContainer from
"@mui/material/TableContainer"
;
import TableHead from
"@mui/material/TableHead"
;
import TableRow from
"@mui/material/TableRow"
;
import Paper from
"@mui/material/Paper"
;
import { TableFooter } from
"@mui/material"
;
import { useState } from
"react"
;
function
createData(index = 0, tutorial =
""
, link =
""
) {
return
{ index, tutorial, link };
}
const rows = [
createData(
1,
"Data Structures"
,
),
createData(
2,
"Algorithms"
,
),
createData(
3,
"Competitive Programming"
,
),
];
function
App() {
const [selectedRow, setSelectedRow] = useState();
return
(
<div className=
"App"
>
<div
className=
"head"
style={{
width:
"fit-content"
,
margin:
"auto"
,
}}
>
<h1
style={{
color:
"green"
,
}}
>
GeeksforGeeks
</h1>
<strong>React MUI TableFooter API</strong>
</div>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }}>
<TableHead>
<TableRow>
<TableCell>Sl. No.</TableCell>
<TableCell>Tutorial</TableCell>
<TableCell>Link</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, index) => (
<TableRow
sx={
index == selectedRow ? { backgroundColor:
"lightcoral"
} : {}
}
onClick={() => {
setSelectedRow(index);
}}
key={row.name}
>
<TableCell component=
"th"
scope=
"row"
>
{row.index}
</TableCell>
<TableCell>{row.tutorial}</TableCell>
<TableCell>
<a href={row.link} target=
"_blank"
>
{row.link}
</a>
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableCell>Total Number of Rows is 3</TableCell>
<TableCell>Number of Selected Rows is {selectedRow}</TableCell>
</TableFooter>
</Table>
</TableContainer>
</div>
);
}
export
default
App;