// ** React Imports
import { useState } from 'react'
// ** MUI Imports
import Box from '@mui/material/Box'
import Card from '@mui/material/Card'
import Button from '@mui/material/Button'
import Typography from '@mui/material/Typography'
import CardHeader from '@mui/material/CardHeader'
import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid'
// ** Custom Components
import CustomChip from 'src/@core/components/mui/chip'
import CustomAvatar from 'src/@core/components/mui/avatar'
// ** Types Imports
import { ThemeColor } from 'src/@core/layouts/types'
// ** Utils Import
import { getInitials } from 'src/@core/utils/get-initials'
// ** Data Import
import { rows } from 'src/@fake-db/table/static-data'
interface StatusObj {
[key: number]: {
title: string
color: ThemeColor
}
}
// ** renders client column
const renderClient = (params: GridRenderCellParams) => {
const { row } = params
const stateNum = Math.floor(Math.random() * 6)
const states = ['success', 'error', 'warning', 'info', 'primary', 'secondary']
const color = states[stateNum]
if (row.avatar.length) {
return
} else {
return (
{getInitials(row.full_name ? row.full_name : 'John Doe')}
)
}
}
const statusObj: StatusObj = {
1: { title: 'current', color: 'primary' },
2: { title: 'professional', color: 'success' },
3: { title: 'rejected', color: 'error' },
4: { title: 'resigned', color: 'warning' },
5: { title: 'applied', color: 'info' }
}
const TableSort = () => {
// ** States
const [isNameSortable, setIsNameSortable] = useState(true)
const [paginationModel, setPaginationModel] = useState({ page: 0, pageSize: 7 })
const columns: GridColDef[] = [
{
flex: 0.275,
minWidth: 290,
field: 'full_name',
headerName: 'Name',
sortable: isNameSortable,
renderCell: (params: GridRenderCellParams) => {
const { row } = params
return (
{renderClient(params)}
{row.full_name}
{row.email}
)
}
},
{
flex: 0.2,
type: 'date',
minWidth: 120,
headerName: 'Date',
field: 'start_date',
sortable: isNameSortable,
valueGetter: params => new Date(params.value),
renderCell: (params: GridRenderCellParams) => (
{params.row.start_date}
)
},
{
flex: 0.2,
minWidth: 110,
field: 'salary',
headerName: 'Salary',
sortable: isNameSortable,
renderCell: (params: GridRenderCellParams) => (
{params.row.salary}
)
},
{
flex: 0.125,
field: 'age',
minWidth: 80,
headerName: 'Age',
sortable: isNameSortable,
renderCell: (params: GridRenderCellParams) => (
{params.row.age}
)
},
{
flex: 0.2,
minWidth: 140,
field: 'status',
headerName: 'Status',
sortable: isNameSortable,
renderCell: (params: GridRenderCellParams) => {
const status = statusObj[params.row.status]
return (
)
}
}
]
return (
}
/>
)
}
export default TableSort