Skip to content

勾选表格行后调用StateHasChanged导致勾选项不一致 #5728

Answered by ArgoZhang
vonser asked this question in Q&A
Discussion options

You must be logged in to vote

@vonser 找到问题了

解决方案如下,请点击下方 Make as answer 按钮标记为答案方便后来人

方案1

增加 [Key] 标签组件会通过这个标签匹配对象是否是同一对象

class UserViewModel
{
    [Key]
    [Display(Name = "用户ID")]
    [AutoGenerateColumn()]
    public string? UserId { get; set; }

    [Display(Name = "用户名")]
    [AutoGenerateColumn()]
    public string? UserName { get; set; }
}

方案2

增加组件参数 ModelEqualityComparer

ModelEqualityComparer="(x, y) => x.UserId == y.UserId"
<Table @ref="ThisTable"
       AutoGenerateColumns="true"
       AllowResizing="true"
       IsStriped="true"
       IsMultipleSelect="true"
       ShowColumnList="true"
       ShowLoading="true"
       ShowToolbar="true"
       ShowRefresh="true"
       ShowEmpty="true"
       ShowExp…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ArgoZhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Question that needs to be answered
2 participants
Converted from issue

This discussion was converted from issue #5649 on March 27, 2025 02:58.