Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Table component merges cells, and when the table is initialized, it will call RowSpan and ColSpan once first, even if my DataSource is empty #3769

Open
dddxiu opened this issue Apr 1, 2024 · 2 comments

Comments

@dddxiu
Copy link

dddxiu commented Apr 1, 2024

Describe the bug

Table 组件有RowSpan,ColSpan属性时,会在初始化的时候调用RowSpan,ColSpan(应该不是这么设计的吧?).如果不返回1,会导致后续数据单元格合并计算错误.

Steps to reproduce (please include code)

GetRowSpan先被调用时,key是null值.

<PropertyColumn Property="c=>c.Tel" Title="Home phone" HeaderColSpan="2" RowSpan="@GetRowSpan(context.Key)" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>

private int GetRowSpan(string key)
  {
    if (key == "3")
      return 2;
    else if (key == "4")
      return 0;
    else
      return 1;
  }

官网的例子刚好返回了1,避过了这个问题.

Exceptions (if any)

后续表格渲染不正确

@ElderJames
Copy link
Member

Thanks for contacting us @dddxiu , please provide a demo to reproduce the issue. I can't guess what your data really are.

@dddxiu
Copy link
Author

dddxiu commented Apr 12, 2024

code like this , from document website.

@using System.ComponentModel

<Table DataSource="@data" Bordered>
  <PropertyColumn Property="c=>c.Name" ColSpan="@GetColSpan(context.Key,"name")"></PropertyColumn>
  <PropertyColumn Property="c=>c.Age" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
  <PropertyColumn Property="c=>c.Tel" Title="Home phone" HeaderColSpan="2" RowSpan="@GetRowSpan(context.Key)" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
  <PropertyColumn Property="c=>c.Phone" HeaderColSpan="0" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
  <PropertyColumn Property="c=>c.Address" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
</Table>

@code {
  Data[] data =  {
    new Data(){ Key="1",Name="John Brown",Age=32,Tel="0571-22098909",Phone="18889898989",Address="New York No. 1 Lake Park"},
    new Data(){Key="2",Name="Jim Green",Tel="0571-22098333",Phone = "18889898888",Age = 42,Address="London No. 1 Lake Park"},
    new Data(){Key="3",Name="Joe Black",Age = 32,Tel="0575-22098909",Phone = "18900010002",Address="Sidney No. 1 Lake Park"},
    new Data(){Key="4",Name="Jim Red",Age = 18,Tel="0575-22098909",Phone = "18900010002",Address="London No. 2 Lake Park"},
    new Data(){Key="5",Name="Jake White",Age = 18,Tel="0575-22098909",Phone = "18900010002",Address="Dublin No. 2 Lake Park"}
  };

  public class Data
  {
    public string Key { get; set; }

    public string Name { get; set; }

    public int Age { get; set; }

    public string Tel { get; set; }

    public string Phone { get; set; }

    public string Address { get; set; }
  }

  private int GetRowSpan(string key)
  {
// there,first render the key when be null
    if (key == "3")
      return 2;
    else if (key == "4")
      return 0;
    else
      return 1;
  }

  private int GetColSpan(string key, string columnTitle = "")
  {
// there,first render the key when be null
    if (key == "5")
      if (columnTitle == "name")
        return 5;
      else
        return 0;
    else
      return 1;
  }
}

@ElderJames ElderJames changed the title Table组件合并单元格,表格初始化的时候会先调用一次RowSpan,ColSpan.即使我的DataSource是空的 The Table component merges cells, and when the table is initialized, it will call RowSpan and ColSpan once first, even if my DataSource is empty Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants