admin管理员组文章数量:1122832
I'm using a MudBlazor DataGrid with cells that use TemplateColumn for custom color. I would like to use EditMode="DataGridEditMode.Cell" for inline editing, but when I do I lose the TemplateColumn.
Is there a way to turn on inline editing only for the selected row? Using DataGridEditTrigger.OnRowClick" does not work.
I'm using a MudBlazor DataGrid with cells that use TemplateColumn for custom color. I would like to use EditMode="DataGridEditMode.Cell" for inline editing, but when I do I lose the TemplateColumn.
Is there a way to turn on inline editing only for the selected row? Using DataGridEditTrigger.OnRowClick" does not work.
https://try.mudblazor.com/snippet/wYcIPPcvKUrbAtTK
Share Improve this question edited Nov 22, 2024 at 2:48 Qiang Fu 8,0731 gold badge6 silver badges16 bronze badges asked Nov 21, 2024 at 18:40 HomerHomer 7,80614 gold badges71 silver badges111 bronze badges 3- Do you mean you don't want the TemplateColumn to be editable? – RBee Commented Nov 21, 2024 at 19:03
- I do want it editable. I'm looking for it to be a textbox when the row is in edit mode and colored text when it is not. – Homer Commented Nov 21, 2024 at 19:35
- You already have that in your snippet though. Can you elaborate on what you're looking for. – RBee Commented Nov 21, 2024 at 22:27
1 Answer
Reset to default 1I think you could use PropertyColumn
instead of TemplateColumn
to make cell inline editing work.
<MudDataGrid Items="@Tests" T="Test" ReadOnly="false" EditMode="DataGridEditMode.Cell" >
<Columns>
<PropertyColumn Property="x => x.Id" Title="Id" />
<PropertyColumn Property="x=>x.Compliant" Title="Compliant"/>
<PropertyColumn Property="x=>x" Title="Compliant Color">
<EditTemplate>
<MudTextField Style="@(context.Item.Compliant.StartsWith("N")?"color: red":"")" @bind-Value="context.Item.Compliant"></MudTextField>
</EditTemplate>
</PropertyColumn>
</Columns>
</MudDataGrid>
@code {
private List<Test> Tests = new()
{
new Test { Id = 1, Compliant = "Yes"},
new Test { Id = 2, Compliant = "No" }
};
public class Test
{
public int Id { get; set; }
public string Compliant { get; set; }
}
}
When you modify the "PropertyColumn" by "EditTemplate", the default template is removed. So it doesn't even matter what the "Property" is, just use Property="x=>x"
.
本文标签:
版权声明:本文标题:asp.net core - In a MudBlazor DataGrid, how can I use inline editing and also use TemplateColumn? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308010a1933509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论