英文:
How to make MudBlazor MudDataGrid horizontal scroll available without having to vertical scroll to bottom of the MudDataGrid displayed rows first?
问题
在 MudBlazor MudDataGrid 中,水平滚动只有在使用垂直滚动将显示的行滚动到底部后才可用。然后,一旦水平滚动可用,用户必须向右滚动以显示所需的列,但然后用户需要垂直滚动回到他们最初需要查看的行。
如何使 MudBlazor MudDataGrid 中的水平滚动始终可用?
<MudDataGrid T="Repair"
Items="@Page.Repairs"
Sortable="true" SortMode="SortMode.Multiple" ColumnResizeMode="ResizeMode.Column"
Filterable="false"
Outlined="true"
Loading="@Page.ProcessingSubmitQuery"
RowsPerPage="10"
Hover="true"
QuickFilter="@QuickFilter">
<ToolBarContent>
<MudText Typo="Typo.body1" Class="mr-1">Job Number:</MudText><MudText Typo="Typo.h6" Class="mr-4">@Page.JobNumber</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Repair Code:</MudText><MudText Typo="Typo.h6" Class="mr-4">@Page.RepairCode</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Customer Id:</MudText><MudText Typo="Typo.h6" Class="mr-8">@Page.CustomerId</MudText>
@*<MudTextField @bind-Value="searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0" />*@
<MudSpacer />
<MudButton Class="ml-4" @onclick="ExportToExcelAsync" Color="Color.Primary" Variant="Variant.Outlined">Export to Excel</MudButton>
</ToolBarContent>
<Columns>
<Column T="Repair" Field="Repair_Id" Sortable="true" Title="#" CellStyle="width: 10px">
<CellTemplate>
<MudLink Href="@GetRepairDetailPageLink(context.Repair_Id)" Target="_blank">
<MudText Style="color:darkblue">@context.Repair_ID</MudText>
</MudLink>
</CellTemplate>
</Column>
<Column T="Repair" Field="Mechanic" Sortable="true" Title="Mechanic" CellStyle="min-width: 10px" />
<Column T="Repair" Field="Description" Sortable="false" Title="Description" CellStyle="min-width: 300px" />
<Column T="Repair" Field="Repair" Sortable="false" Title="Repair Made" CellStyle="min-width: 200px" />
</Columns>
<PagerContent>
<MudDataGridPager T="Repair" PageSizeOptions@(new int[] {10, 25, 50, 100, 150, 200 }) />
</PagerContent>
</MudDataGrid>
英文:
In the MudBlazor MudDataGrid, the horizontal scroll is unavailable unless the vertical scroll is used to scroll to the bottom of the displayed rows in the MudDataGrid. Then once the horizontal scroll is available, the user must scroll to the right to expose the needed columns, but then the user needs to vertical scroll back up to the rows they needed to view to begin with.
How do I make the MudBlazor MudDataGrid horizontal scroll available all the time?
<MudDataGrid T="Repair"
Items="@Page.Repairs"
Sortable="true" SortMode="SortMode.Multiple" ColumnResizeMode="ResizeMode.Column"
Filterable="false"
Outlined="true"
Loading="Page.ProcessingSubmitQuery"
RowsPerPage="10"
Hover="true"
QuickFilter="@QuickFilter">
<ToolBarContent>
<MudText Typo="Typo.body1" Class="mr-1">Job Number:</MudText><MudText Typo="Typo.h6" Class="mr-4">@Page.JobNumber</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Repair Code:</MudText><MudText Typo="Typo.h6" Class="mr-4">@Page.RepairCode</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Customer Id:</MudText><MudText Typo="Typo.h6" Class="mr-8">@Page.CustomerId</MudText>
@*<MudTextField @bind-Value="searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0" />*@
<MudSpacer />
<MudButton Class="ml-4" @onclick="ExportToExcelAsync" Color="Color.Primary" Variant="Variant.Outlined">Export to Excel</MudButton>
</ToolBarContent>
<Columns>
<Column T="Repair" Field="Repair_Id" Sortable="true" Title="#" CellStyle="width: 10px" h>
<CellTemplate>
<MudLink Href="@GetRepairDetailPageLink(context.Repair_Id)" Target="_blank">
<MudText Style="color:darkblue">@context.Repair_ID</MudText>
</MudLink>
</CellTemplate>
</Column>
<Column T="Repair" Field="Mechanic" Sortable="true" Title="Mechanic" CellStyle="min-width: 10px" />
<Column T="Repair" Field="Description" Sortable="false" Title="Description" CellStyle="min-width: 300px" />
<Column T="Repair" Field="Repair" Sortable="false" Title="Repair Made" CellStyle="min-width: 200px" />
</Columns>
<PagerContent>
<MudDataGridPager T="Repair" PageSizeOptions=@(new int[] {10, 25, 50, 100, 150, 200 }) />
</PagerContent>
</MudDataGrid>
答案1
得分: 2
你可以通过将HorizontalScrollbar设置为true并添加CSS到你的DataGrid来解决这个问题。以下是翻译好的代码部分:
<MudDataGrid T="Repair" Items="@repairs" Sortable="true" SortMode="SortMode.Multiple" ColumnResizeMode="ResizeMode.Column" Filterable="false" Outlined="true"
RowsPerPage="10" Hover="true" HorizontalScrollbar="true" Style="max-height: 500px; max-width: 600px; overflow: scroll;">
<ToolBarContent>
<MudText Typo="Typo.body1" Class="mr-1">Job Number:</MudText><MudText Typo="Typo.h6" Class="mr-4">job #</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Repair Code:</MudText><MudText Typo="Typo.h6" Class="mr-4">repair code</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Customer Id:</MudText><MudText Typo="Typo.h6" Class="mr-8">customer id</MudText>
<MudSpacer />
<MudButton Class="ml-4" @onclick="ExportToExcelAsync" Color="Color.Primary" Variant="Variant.Outlined">Export to Excel</MudButton>
</ToolBarContent>
<Columns>
<Column T="Repair" Field="Repair_Id" Sortable="true" Title="#" CellStyle="width: 10px">
<CellTemplate>
<MudLink Href="#">
<MudText Style="color: darkblue">@context.Item.Repair_Id</MudText>
</MudLink>
</CellTemplate>
</Column>
<Column T="Repair" Field="Mechanic" Sortable="true" Title="Mechanic" CellStyle="min-width: 10px" />
<Column T="Repair" Field="Description" Sortable="false" Title="Description" CellStyle="min-width: 300px" />
<Column T="Repair" Field="RepairsMade" Sortable="false" Title="Repair Made" CellStyle="min-width: 200px" />
</Columns>
<PagerContent>
<MudDataGridPager T="Repair" PageSizeOptions="new int[] {10, 25, 50, 100, 150, 200 }" />
</PagerContent>
</MudDataGrid>
你可以点击以下链接查看MudBlazor示例,以查看它的工作原理(只需点击左上角的播放按钮加载它):https://try.mudblazor.com/snippet/cYQHYGGHCGuEaJEO
英文:
You should be able to solve this by setting HorizontalScrollbar to true and adding css to your datagrid:
<MudDataGrid T="Repair" Items="@repairs" Sortable="true" SortMode="SortMode.Multiple" ColumnResizeMode="ResizeMode.Column" Filterable="false" Outlined="true"
RowsPerPage="10" Hover="true" HorizontalScrollbar="true" Style="max-height: 500px; max-width: 600px; overflow: scroll;">
<ToolBarContent>
<MudText Typo="Typo.body1" Class="mr-1">Job Number:</MudText><MudText Typo="Typo.h6" Class="mr-4">job #</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Repair Code:</MudText><MudText Typo="Typo.h6" Class="mr-4">repair code</MudText>
<MudText Typo="Typo.body1" Class="mr-1">Customer Id:</MudText><MudText Typo="Typo.h6" Class="mr-8">customer id</MudText>
<MudSpacer />
<MudButton Class="ml-4" @onclick="ExportToExcelAsync" Color="Color.Primary" Variant="Variant.Outlined">Export to Excel</MudButton>
</ToolBarContent>
<Columns>
<Column T="Repair" Field="Repair_Id" Sortable="true" Title="#" CellStyle="width: 10px" h>
<CellTemplate>
<MudLink Href="#" Target="_blank">
<MudText Style="color: darkblue">@context.Item.Repair_Id</MudText>
</MudLink>
</CellTemplate>
</Column>
<Column T="Repair" Field="Mechanic" Sortable="true" Title="Mechanic" CellStyle="min-width: 10px" />
<Column T="Repair" Field="Description" Sortable="false" Title="Description" CellStyle="min-width: 300px" />
<Column T="Repair" Field="RepairsMade" Sortable="false" Title="Repair Made" CellStyle="min-width: 200px" />
</Columns>
<PagerContent>
<MudDataGridPager T="Repair" PageSizeOptions=@(new int[] {10, 25, 50, 100, 150, 200 }) />
</PagerContent>
</MudDataGrid>
You can check out this MudBlazor snippet to see it working (just click the play button in the top left to load it): https://try.mudblazor.com/snippet/cYQHYGGHCGuEaJEO
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论