MUI Data Grid horizontal scrolling (responsiveness) is not working - reactjs

I created a Data Grid table with 10 columns. It looks great on big screens but when I squeeze it below 1380 px, I expect to see a horizontal bar scrolling but it looks terrible.
I don't want to switch to another library and just need to fix this horizontal scrolling problem. In the docs, it works perfectly. But I use renderCell and I think that cause the problem. But couldn't solve it still.
Here is how it looks like in big screens:
Here how it looks like at 1303 px:
And here on mobile sizes it can scroll but its sequeezed a lot and looks terrible:
I tried many suggestions on stack but couldn't find any solution still.
Here is my styled DataGrid props:
<DataGridStyled
rows={getRowData()}
autoHeight
rowHeight={80}
columns={columns}
rowsPerPageOptions={[5, 10, 15, 30, 100]}
pageSize={pageSize}
onPageSizeChange={(newPageSize) => setPageSize(newPageSize)}
checkboxSelection
disableSelectionOnClick
pagination
scrollbarSize={50}
/>
Here is the 5th column (I used renderCell maybe its because of this?):
{
field: 'bloodPressure',
headerName: 'BP (mmHg)',
headerAlign: 'center',
align: 'center',
type: 'string',
flex: 1,
editable: false,
valueGetter: (params) =>
params?.row?.bloodPressure?.lastSys === undefined
? null
: params?.row?.bloodPressure?.lastSys,
renderCell: (params) => {
return (
<Tooltip
sx={{ cursor: 'pointer' }}
followCursor
title={
params.row?.bloodPressure?.lastDate === undefined
? 'No measurement'
: moment(params.row?.bloodPressure?.lastDate).fromNow()
}
>
<Box
display="flex"
alignItems="center"
justifyContent="center"
width={'60%'}
bgcolor={params.row?.bloodPressure?.riskColor}
borderRadius={1}
py={0.3}
>
<Typography variant="subtitle1" color="black">
{params.row?.bloodPressure?.lastSys === undefined ||
params.row?.bloodPressure?.lastDia === undefined
? '--'
: `${params.row?.bloodPressure?.lastSys?.toFixed(
0
)}/${params.row?.bloodPressure?.lastDia?.toFixed(0)}`}
</Typography>
<Typography
variant="subtitle1"
color="black"
sx={{
display: 'flex',
alignItems: 'center'
}}
>
{params.row?.bloodPressure?.lastSys === undefined &&
params.row?.bloodPressure?.lastDia === undefined ? null : params
.row?.bloodPressure?.lastSys +
params.row?.bloodPressure?.lastDia >
params.row?.bloodPressure?.previousSys +
params.row?.bloodPressure?.previousDia ? (
<ArrowUpwardIcon
sx={{
fontSize: 14,
lineHeight: 1.75,
height: '100%'
}}
/>
) : (
<ArrowDownwardIcon
sx={{
fontSize: 14,
lineHeight: 1.75,
height: '100%'
}}
/>
)}
</Typography>
</Box>
</Tooltip>
);
}
},

Related

React MUI Collapse component ignores timeout and acts as if timeout is 0

I'm using React, Typescript with MUI and I wanted to make a burger menu where each clicking on an option smoothly opens a <Box> component, which contains additional options. What happens is that it ignores the timeout={2000} prop and just displays it as if it's display is none and then gets turned into display:block for example.
const [badgeMenuOpen, setBadgeMenuOpen] = useState<boolean>(false);
const [badgeMenuOpen1, setBadgeMenuOpen1] = useState<boolean>(false);
const [badgeMenuOpen2, setBadgeMenuOpen2] = useState<boolean\>(false);
const handleMenuClick = () => {
if (badgeMenuOpen) {
setBadgeMenuOpen(false);
} else {
setBadgeMenuOpen(true);
}
};
const handleMenu1Click = () => {
if (badgeMenuOpen1) {
setBadgeMenuOpen1(false);
} else {
setBadgeMenuOpen1(true);
}
};
const handleMenu2Click = () => {
if (badgeMenuOpen2) {
setBadgeMenuOpen2(false);
} else {
setBadgeMenuOpen2(true);
}
};
<IconButton
size="medium"
edge="start"
sx={{ color: "#0073d1" }}
aria-label="sidebar-logo"
onClick={handleSideMenuClick}
/>
<Typography>menu\</Typography>
<MenuIcon\>
<IconButton\>
<StyledDrawer
open={sideMenuOpen}
anchor="right"
hideBackdrop={true}
aria-controls={sideMenuOpen ? "sidebar-logo" : undefined}
aria-expanded={sideMenuOpen ? true : false}
sx={{ marginTop: "60px", backgroundColor: "#f8f8f" }}
onClose={() =\> {
setSideMenuOpen(false);
}}
id="MUI-drawer"
\>
<Box minWidth={"100%"} role="presentation"\>
<List
disablePadding={true}
sx={{ minWidth: "100%", display: "flex", flexDirection: "column" }}
\>
<ListItem sx={{ display: "flex", justifyContent: "center" }}>
<RouterLink
className="header__phone-menu__item__submenu__item"
to="/home"
\>
{t("exampletext")}
</RouterLink\>
<Divider /\>
</ListItem\>
<Divider /\>
<ListItem
disablePadding={true}
sx={{
display: "flex",
flexDirection: "column",
backgroundColor: badgeMenuOpen1 ? "#fff" : "#f8f8f",
}}
\>
<StyledBadge
onClick={handleMenu1Click}
id={"badgeMenu"}
color="error"
invisible={false}
badgeContent={"!"}
sx={{
display: "flex",
flexDirection: "column",
}}
className="header__phone-menu__item__submenu-toggle"
\>
{t("exampletext")}
</StyledBadge>
<Box
sx={{ height: badgeMenuOpen1 ? "100%" : "0px" }}
id="badgeId"
className="header__phone-menu__item__submenu"
\>
<RouterLink
className="header__phone-menu__item__submenu__item"
to="/cards"
\>
{t("exampletext")}
</RouterLink\>
I tried using <Fade> component, which actually worked, but it just changed it's opacity to 0 so the space was still occupied and that doesn't quite work for me.
Are there any specific parents that the `<Collapse>` component has to be inside for it to work?
--EDIT-- Ignore the \ inside the code, stackoverflow formated it somehow

How can I use react-native-picker horizontally?

Hi i want to use https://github.com/react-native-picker/picker library horizontally. I also found some picker libraries that can be used horizontally but none of them works as stable as this native picker. I tried to give style transform rotate 90 deg but it caused the view below
And I couldnt reach text style to rotate it -90 deg.
I tried to download library and edit it but it's objective c and I don't know nothing about it. How can I do that any ideas?
My picker code
<Picker style={{
width: 100,
position: 'absolute',
right:50,
}}
itemStyle={{
fontSize: 20,
width: 100,
transform: [{ rotate: '90deg' }],
}}
selectedValue={Value}
onValueChange={(itemValue, itemIndex) => {
setValue(+itemValue);
}}
>
{Values.map(item => (
<Picker.Item
key={item.key}
label={item.value}
value={item.key}
></Picker.Item>
))}
</Picker>
I tried to edit the PickerItem.js in library like below but it didn't work
export default function PickerItem({
color,
label,
testID,
value,
enabled = true,
}: Props): React.Node {
return (
<Option
disabled={enabled === false ? true : undefined}
style={{color}}
testID={testID}
value={value}
label={label}>
<Text style={{transform: '-90deg', backgroundColor: 'red'}}>
{label}
</Text>
</Option>
);
}
and also I tried to add
label.transform = CGaffineTransformMakeRotation(M_PI / 2);
to RNCPicker.m

How to add a "dot" below a DatePicker?

I'm currently needing to show a little "dot" below some dates on MUIX DatePicker, something like this.
May someone help me?
Thank you
You can do it by manipulating ‍‍‍‍renderDay prop in DatePicker component.
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
label="Basic example"
value={value}
onChange={(newValue) => {
setValue(newValue);
}}
renderInput={(params) => <TextField {...params} />}
renderDay={(day, _value, DayComponentProps) => {
return (
<Badge
key={day.toString()}
overlap="circular"
badgeContent={
(!DayComponentProps.outsideCurrentMonth && [1, 3, 23].some(x => x === day.date())) ? "⚫" : undefined}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right'
}}
sx={{
'& .MuiBadge-badge': {
right: '50%'
}
}}
>
<PickersDay {...DayComponentProps} />
</Badge>
);
}}
/>
</LocalizationProvider>
Notice that, by means of :
anchorOrigin = {{
vertical: 'bottom',
horizontal: 'right'
}}
sx = {{
'& .MuiBadge-badge': {
right: '50%'
}
}}
I placed the dot (bullet) at the center bottom of the days number.
Also this means :
badgeContent = {
(!DayComponentProps.outsideCurrentMonth && [1, 3, 23].some(x => x === day.date())) ? "⚫" : undefined
}
If the days that are being shown in the calendar frame are neither related to the current month nor in [1, 3, 23](Which naturally depends on your choice), do not show the dot.

Set <Avatar> backgroundColor randomly

I have defined three backgroundColor in the style theme.
avatar: {
backgroundColor: red[500],
},
orangeAvatar: {
margin: 10,
color: '#fff',
backgroundColor: deepOrange[500],
},
purpleAvatar: {
margin: 10,
color: '#fff',
backgroundColor: deepPurple[500],
},
When ever the Avatar is loaded I would like to select one of them randomly.
<Card>
<CardHeader
avatar={
<Avatar id="av" aria-label="Recipe"
className={classes.avatar}>{this.props.userName.charAt(0).toLocaleUpperCase()}
</Avatar>}
title={this.props.userName} disableTypography={true}/>
<CardActionArea disabled={this.state.images.length == 1 ? true : false}>
<CardMedia
id={this.props.ownerId}
className={classes.media}
image={this.state.images[this.state.imageIndex]}
onClick={this.handleOnClick}
/>
</CardActionArea>
</Card>
Any advice how to do this?
Thank you
Several ways to do what you want. My suggestion: put the 3 classes in an array, pick a random number between 0 and 2 every time, and assign that class name:
<Avatar className={classes[Math.floor(Math.random() * 3)]}.../>
I was presented with the same need, perhaps this solution will also serve you, there is a function to generate the color at random and then call the function from the online style.
const useStyles = makeStyles((theme: Theme) =>
createStyles({
large: {
fontSize: "2.5rem",
width: 100,
height: 100
}
})
);
function randomColor() {
let hex = Math.floor(Math.random() * 0xFFFFFF);
let color = "#" + hex.toString(16);
return color;
}
...
return (
<Avatar
variant="square"
src={imageSrc}
alt={alt}
className={classes.large}
style={{
backgroundColor: randomColor()
}}
/>
)
ref:
Javascript random color
Avatar random backgroundColor on fallback
let classNameHolder = ["avatar","orangeAvatar","purpleAvatar"];
<Card>
<CardHeader
avatar={
<Avatar id="av" aria-label="Recipe"
className={classNameHolder[Math.floor(Math.random() * 3)]}>{this.props.userName.charAt(0).toLocaleUpperCase()}
</Avatar>}
title={this.props.userName} disableTypography={true}/>
<CardActionArea disabled={this.state.images.length == 1 ? true : false}>
<CardMedia
id={this.props.ownerId}
className={classes.media}
image={this.state.images[this.state.imageIndex]}
onClick={this.handleOnClick}
/>
</CardActionArea>
</Card>

How to reduce gap between Stars in material UI

I am trying to reduce gap between stars but no luck.
Code below for your ref
<MuiThemeProvider >
<Rating
onChange={() => console.log('onChange')}
value={4}
max={5}
iconFilled={<ToggleStar color={colors.green500} />}
iconHovered={<ToggleStarBorder color={colors.green500} />}
iconNormal ={<ToggleStarBorder color={colors.black300}/>}
className={classes.Rating}
spacing ={0}
onChange={(value) => console.log(`Rated with value ${value}`)}
/>
</MuiThemeProvider >
How can I resolve this?
Use the itemStyle and itemIconStyle props:
const smallDistanceStyle = {
width: 30,
height: 30,
padding: 5
}
const iconStyle = {
width: ...,
height: ...
}
<Rating
itemStyle={smallDistanceStyle}
itemIconStyle={iconStyle}
...
/>
I know this question was asked a while ago, but I found that
<Rating
value={5}
readOnly
sx={{
fontSize: "5rem",
"& .MuiRating-icon": {
width: '4.5rem'
}
}}
icon={<StarRateIcon fontSize="5rem" sx={{ color: "black" }} />}
/>
worked for me. It was able to bring the stars a little closer together.

Resources