question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The HashCode of DataSource has not changed whenselecting and deleting all

See original GitHub issue

Describe the bug

我在使用table时,当我全选数据后,执行删除操作,我将通过对话框的方式确认数据是否删除,当点击对话框的确认按钮后,数据是真实的删除了,但是神奇的是table居然没有变化(我在执行完删除操作后进行了查询处理)

复现代码

@page "/"
@using AntDesign.TableModels;

<div>
    <Button OnClick="Delete">删除</Button>
    <Button OnClick="Delete1">删除1</Button>
    <Button OnClick="Add">新增</Button>

    <Table 
           TItem="Column"
           DataSource="@_vmTableModel.Source"
           @bind-SelectedRows="_vmTableModel.Selected"
           RenderMode="RenderMode.ParametersHashCodeChanged"
           OnChange="@OnDataChange"
           Loading=@(_vmTableModel.Source==null)
           Size="TableSize.Small"
           HidePagination
           EnableVirtualization
           ScrollY="calc(100vh-200px)"
           ScrollX="1200"
           Bordered>
        <Selection Key="@context.Name"  />
        <PropertyColumn Property="c=>c.Name">
            <a>@context.Name</a>
        </PropertyColumn>
        <PropertyColumn Property="c=>c.Age" />
        <PropertyColumn Property="c=>c.Address" />
    </Table>
</div>

<Modal Title="@("删除提示")"
       Draggable="true"
       Visible="@_delModal.Visible"
       OnOk="@DeleteHandleOk"
       OnCancel="@CloseModal"
       ConfirmLoading="@_delModal.Loading">
    <p>是否删除选中的数据</p>
</Modal>
@code {
    public class ModalModel
    {
        public bool Visible { get; set; }
        public bool Loading { get; set; }
    }
    private ModalModel _delModal = new ModalModel();
    private TableModel<Column> _vmTableModel = new(null, null);
    protected void CloseModal(MouseEventArgs e)
    {
        _delModal.Visible = false;
    }
    protected async Task DeleteHandleOk(MouseEventArgs e)
    {
        _delModal.Loading = true;
        var keys = _vmTableModel.Selected.Select(b => b.Name).ToList();
        data.Where(b => keys.Contains(b.Name)).ToList().ForEach(b => data.Remove(b));
        _vmTableModel.Source = null;
        _vmTableModel.Source = data;
        _delModal.Visible = false;
        _delModal.Loading = false;

    }
    ITable table;
    public class TableModel<T>
    {
        public TableModel(List<T>? source, IEnumerable<T>? selected)
        {
            Source = source;
            Selected = selected;
        }

        public List<T>? Source { get; set; }

        public IEnumerable<T>? Selected { get; set; }
    }
    class Column
    {

        public string Name { get; set; }

        public int Age { get; set; }

        public string Address { get; set; }
    }

    public void Delete()
    {
        _delModal.Visible = true;
    }
    public void Delete1()
    {
        var keys = _vmTableModel.Selected.Select(b => b.Name).ToList();
        data.Where(b => keys.Contains(b.Name)).ToList().ForEach(b => data.Remove(b));
        _vmTableModel.Source = null;
        _vmTableModel.Source = data;
    }
    public void Add()
    {
        _vmTableModel.Source = null;
        data.Add(new Column
            {
                Name = Guid.NewGuid().ToString(),
                Age = 1
            });
        _vmTableModel.Source = data;
    }
    List<Column> data =new()
    {
        new Column()
        {
            Name = "John Brown",
            Age = 32,
            Address = "New York No. 1 Lake Park",
        },
        new Column()
        {
            Name = "Jim Green",
            Age = 42,
            Address = "London No. 1 Lake Park",
        },
        new Column()
        {
            Name = "Joe Black",
            Age = 32,
            Address = "Sidney No. 1 Lake Park",
        },
        new Column()
        {
            Name = "Disabled User",
            Age = 99,
            Address = "Sidney No. 1 Lake Park",
        }
    };

    string selectionType = "checkbox";
    void OnDataChange(QueryModel<Column> query)
    {
        _vmTableModel.Source = data;
    }
   
}

Further technical details

  • AntDesign 版本0.15.0

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zxyao145commented, Jun 9, 2023

@XueDee123 hi, I debugged the program and found that it is very interesting that this issue only occurs when selecting and deleting all, then I found that the Table has rewritten ‘ShouldRender’, and you set RenderMode='RenderMode. ParametersHashCodeChanged', but the HashCode of DataSource has not changed, so the Table’s re-rendering is blocked.

The solution to this problem is set RenderMode='RenderMode.Always'. Perhaps there are other better solutions, but I haven’t found them.

@ElderJames In principle, resetting _ VmTableModel=new (data, null) each time will also cause the hash to change, but it’s not, please pay attention to this issue.

0reactions
ElderJamescommented, Jun 18, 2023

@XueDee123 For now, please call _table.ReloadData for workaround.

    protected async Task DeleteHandleOk(MouseEventArgs e)
    {
        _delModal.Loading = true;
        var keys = _vmTableModel.Selected.Select(b => b.Name).ToList();
        data.Where(b => keys.Contains(b.Name)).ToList().ForEach(b => data.Remove(b));
        _vmTableModel.Source = null;
        _vmTableModel.Source = data;
        _delModal.Visible = false;
        _delModal.Loading = false;
+       _table.ReloadData();
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - hashCode does not change in the method when ...
hashCode does not change in the method when changing parameters. That is normal behavior for Object.hashCode . And your Cat method is using ......
Read more >
2 Issues Resolved by Hot Fix Releases
Root Cause: When the user tries to change the status, and the next status is Released or Complete, the system checks whether or...
Read more >
Known and Corrected issues in version 12.1.02
When attempting to move a ticket from a Saved Search view from a Custom Console, after selecting the Container and Item to move...
Read more >
Jdbi 3 Developer Guide
Jdbi is not an ORM. There is no session cache, change tracking, "open session in view", or cajoling the library to understand your...
Read more >
Mendix Studio pro
When selecting an association, the selectable object data source is configured with a default database source. Switching from a database to an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found