-
I have implemented a muddatagrid to view and edit records (it has a boolean member using checkboxes to display it) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
You can supply an EditTemplate to tell the MudDataGrid to show the value as a checkbox. IsDisabled is a Boolean in this example.
|
Beta Was this translation helpful? Give feedback.
-
Hi, Damon, |
Beta Was this translation helpful? Give feedback.
-
Thank you for posting this information @Damon-Josko !!! It helped me get the checkbox in place. However, I'm facing an issue trying to get the CommittedItemChanges event handler to work. It's throwing this error when I try to replicate "Argument 2: cannot convert from 'method group' to 'Microsoft.AspNetCore.Components.EventCallback'" Do you have any suggestions on what I'm doing incorrectly please? Below is the snippit of code.
|
Beta Was this translation helpful? Give feedback.
-
Hello, I know this is a reasonably old discussion, but if you search for "MudDataGrid checkbox", this is the top result. So I thought I would share an alternative solution that worked for me, as nothing else did. It was explained to me by someone in Reddit, so credit to them. Using Blazor 8, and MudBlazor 7.8.0. Key Take Aways
The ExampleSomewhere in your project: public class SomeDataClass
{
public string Name { get; set; }
public bool IsActive { get; set; }
} And in your razor file: @if (Order == null)
{
<MudCard>
<MudCardActions>
<MudSkeleton Width="64px" Height="40px" Class="ml-2" />
<MudSkeleton Width="105px" Height="40px" Class="ml-3" />
</MudCardActions>
</MudCard>
}
else
{
<MudDataGrid
T="SomeDataClass"
Items="@ListOfSomeData"
Virtualize="true"
Height="50%"
FixedHeader="true"
ReadOnly="false"
EditMode="DataGridEditMode.Cell"
Bordered="true"
Dense="false"
SortMode="SortMode.None"
Filterable="false"
EditTrigger="DataGridEditTrigger.Manual">
<Columns>
<PropertyColumn Property="x => x.Name"></PropertyColumn>
<TemplateColumn Title="Is Active">
<CellTemplate>
<MudCheckBox T=bool @bind-Value=context.Item.IsActive ReadOnly="true" ></MudCheckBox>
</CellTemplate>
<EditTemplate>
<MudCheckBox T=bool @bind-Value=context.Item.IsActive ></MudCheckBox>
</EditTemplate>
</TemplateColumn>
</Columns>
</MudDataGrid>
}
@code {
[Parameter]
public IEnumerable<SomeDataClass>? ListOfSomeData { get; set; }
}
|
Beta Was this translation helpful? Give feedback.
-
Use
|
Beta Was this translation helpful? Give feedback.
You can supply an EditTemplate to tell the MudDataGrid to show the value as a checkbox. IsDisabled is a Boolean in this example.
<MudDataGrid>
<Columns>
<PropertyColumn Property="x => x.DemoId" Title="Id" IsEditable="false" />
<PropertyColumn Property="x => x.Name" IsEditable="true" />
<PropertyColumn Property="x => x.IsDisabled" IsEditable="true">
<EditTemplate>
<MudCheckBox @bind-Checked="context.Item.IsDisabled" />
</EditTemplate>
</PropertyColumn>
</Columns>
</MudDataGrid>