Я пытаюсь отобразить данные в удобной для глаза форме, но с трудом могу правильно их построить.
Я хочу отформатировать страницу следующим образом: 1-я сетка содержит 3 текстовых поля, одно под другим с соответствующим заголовком над всеми. 2-я сетка такая же, как и 3 других поля, а 3-я сетка содержит 7 текстовых полей, которые я хочу отобразить -> 3 в первом столбце, 2 во втором, 2 и последнем, все под одним заголовком.
Если я помещу все 7 последних полей в одну сетку, все они появятся в одном столбце. Сейчас это почти работает, но только первые 3 текстовых поля правильно отведены под заголовком, а остальные 4 отображаются на другом поле.
Это мой код: (если у кого-то есть идея улучшить отображение, я более чем открыт, чтобы услышать об этом)
<Grid container spacing = {24}>
<Grid item sm = {3}> // First grid - contains 3 text fields
<Typography variant = "subheading" gutterBottom color = "primary" >
{labels.brokerGeneralDetails}
</Typography>
<Grid item sm = {10}>
<TextField
...
/>
</Grid>
<Grid item sm = {2}>
<TextField
...
/>
</Grid>
<Grid item sm = {2}>
<TextField
...
/>
</Grid>
</Grid>
<Grid item sm = {1}> // Second grid - contains 3 text fields
<Typography variant = "subheading" gutterBottom color = "primary">
{labels.brokerAccountDetails}
</Typography>
<Grid item sm = {6}>
<TextField
...
/>
</Grid>
<Grid item sm = {3}>
<TextField
...
/>
</Grid>
<Grid item sm = {2}>
<TextField
...
/>
</Grid>
</Grid>
<Grid item sm = {3}> // Third grid - Should contain 7 text fields in 3 columns
<Typography variant = "subheading" gutterBottom color = "primary">
{labels.brokerOtherDetails}
</Typography>
<Grid >
<TextField
...
/>
</Grid>
<Grid item sm = {2}>
<TextField
...
/>
</Grid>
<Grid item sm = {1}>
<TextField
...
/>
</Grid>
</Grid>
<Grid item sm = {1}> // Should be the second column
<Grid>
<TextField
...
/>
</Grid>
<Grid >
<TextField
...
/>
</Grid>
</Grid>
<Grid item sm = {1}> // Should be the third column
<Grid>
<TextField
...
/>
</Grid>
<Grid>
<TextField
...
/>
</Grid>
</Grid>
</Grid>
Я хочу, чтобы он отображался следующим образом:
Title3 Title2 Title1
Txt6 Txt4 Txt1 Txt1 Txt1
Txt7 Txt5 Txt2 Txt2 Txt2
Txt3 Txt3 Txt3
Прямо сейчас это:
Txt6 Txt4 Title3 Title2 Title1
Txt7 Txt5 Txt1 Txt1 Txt1
Txt2 Txt2 Txt2
Txt3 Txt3 Txt3
Картинка текущего дисплея? @SakhiMansoor
Нет, я имею в виду желаемый результат
@SakhiMansoor Обновлено
Я добавил ответ ниже. Надеюсь это поможет



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Я не уверен, что это лучший способ построить сетку на основе того, что вы хотите, но я бы сделал это так:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = "*"/>
<ColumnDefinition Width = "*"/>
<ColumnDefinition Width = "*"/>
<ColumnDefinition Width = "*"/>
<ColumnDefinition Width = "*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height = "*"/>
<RowDefinition Height = "*"/>
<RowDefinition Height = "*"/>
<RowDefinition Height = "*"/>
</Grid.RowDefinitions>
<Label Grid.Column = "2" Content = "Title3" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "3" Content = "Title2" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "4" Content = "Title1" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "0" Grid.Row = "1" Content = "Txt6" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "1" Grid.Row = "1" Content = "Txt4" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "2" Grid.Row = "1" Content = "Txt1" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "3" Grid.Row = "1" Content = "Txt1" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "4" Grid.Row = "1" Content = "Txt1" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "0" Grid.Row = "2" Content = "Txt7" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "1" Grid.Row = "2" Content = "Txt5" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "2" Grid.Row = "2" Content = "Txt2" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "3" Grid.Row = "2" Content = "Txt2" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "4" Grid.Row = "2" Content = "Txt2" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "2" Grid.Row = "3" Content = "Txt3" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "3" Grid.Row = "3" Content = "Txt3" HorizontalAlignment = "Center" FontSize = "36"/>
<Label Grid.Column = "4" Grid.Row = "3" Content = "Txt3" HorizontalAlignment = "Center" FontSize = "36"/>
</Grid>
Результат выглядит так: https://gyazo.com/b6768ab550ddac6685549c35e38b34e9
Вы также можете использовать Grid.ColumnSpan для охвата нескольких столбцов вашей сетки, если вы хотите центрировать заголовок над всеми 5 столбцами.
Используйте alignItems в своей сетке: alignItems = "center"
<Grid container spacing = {24} alignItems = "center">
Потратив некоторое время, я думаю, что сделал это: вот коды и ящик: https://codesandbox.io/s/ll507vypy7
код:
const styles = theme => ({
root: {
flexGrow: 1
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
width: 50
}
});
class TextFields extends React.Component {
render() {
const { classes } = this.props;
return (
<div className = {classes.root}>
<Grid container>
<Grid item container xs = {4}>
<Grid item xs = {12}>
<Typography variant = "subheading" gutterBottom color = "primary">
Grid1
</Typography>
</Grid>
<Grid item xs = {12}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {12}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {12}>
<TextField className = {classes.textField} />
</Grid>
</Grid>
<Grid item container xs = {4}>
<Grid item xs = {12}>
<Typography variant = "subheading" gutterBottom color = "primary">
Grid2
</Typography>
</Grid>
<Grid item xs = {12}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {12}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {12}>
<TextField className = {classes.textField} />
</Grid>
</Grid>
<Grid container item xs = {4}>
<Grid item xs = {12}>
<Typography variant = "subheading" gutterBottom color = "primary">
Grid3
</Typography>
</Grid>
<Grid container item xs = {12}>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
</Grid>
<Grid container item xs = {12}>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
</Grid>
<Grid container item xs = {12}>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
<Grid item xs = {4}>
<TextField className = {classes.textField} />
</Grid>
</Grid>
</Grid>
</Grid>
</div>
);
}
}
PS это МАТЕРИАЛ-UI
можно сюда прикрепить дизайн?