简体   繁体   English

如何使用 EditTemplate 绑定到 Blazorise DataGrid 中的 TextEdit

[英]How to bind to a TextEdit in Blazorise DataGrid using EditTemplate

I am new to Blazor and Blazorise...and while studying this component, I can't seem to find any material teaching how to bind a variable in a TextEdit inside an EditTemplate of a Blazorise DataGrid..我是 Blazor 和 Blazorise 的新手......在研究这个组件时,我似乎找不到任何材料教如何在 Blazorise DataGrid 的 EditTemplate 内的 TextEdit 中绑定变量。

Inside my Blazorise DataGrid, I have a DataColumn (see code below):在我的 Blazorise DataGrid 中,我有一个 DataColumn(请参见下面的代码):

<DataGridColumn
    Caption="Description"
    Editable="true"
    TItem="ProductVo"
    Field="@nameof(ProductVo.Description)">
        <DisplayTemplate>
            @($"{(context as ProductVo)?.Description}")
        </DisplayTemplate>
        <EditTemplate>
            <Validation UsePattern="true">              
                <TextEdit @bind-Text="context.CellValue" Text="@((string)context.CellValue)" Pattern="^.{3,200}$">
                    <Feedback>
                        <ValidationError>This field must be between 3 and 200 characters long.</ValidationError>
                    </Feedback>
                </TextEdit>
            </Validation>
        </EditTemplate>
</DataGridColumn>

In my <TextEdit> , I can display the value when editing by using the following code:在我的<TextEdit>中,我可以使用以下代码在编辑时显示该值:

Text="@((string)context.CellValue)"

But it does not save, because I can't bind the context.CellValue using @bind-Text="context.CellValue" .但它不会保存,因为我无法使用@bind-Text="context.CellValue" context.CellValue

Please help me learn how to use Blazorise DataGrid, thanks in advance!请帮助我学习如何使用 Blazorise DataGrid,在此先感谢!

You're missing the TextChanged event, responsable to update the text on the context .您缺少TextChanged事件,负责更新context上的文本。 This should work:这应该有效:

<TextEdit Text="@((string)context.CellValue)" TextChanged="@(v => ( (CellEditContext)context ).CellValue = v)" Pattern="^.{3,200}$">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM