2020-06-19 23:06:33 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
using System.Linq;
|
2020-06-19 23:06:33 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public class ColumnContext
|
|
|
|
|
{
|
|
|
|
|
public IList<IColumn> Columns { get; set; } = new List<IColumn>();
|
|
|
|
|
|
2021-01-11 13:39:02 +08:00
|
|
|
|
public IList<IColumn> HeaderColumns { get; set; } = new List<IColumn>();
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
private int CurrentColIndex { get; set; }
|
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
private ITable _table;
|
|
|
|
|
|
|
|
|
|
public ColumnContext(ITable table)
|
|
|
|
|
{
|
|
|
|
|
_table = table;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 13:39:02 +08:00
|
|
|
|
public void AddColumn(IColumn column)
|
2020-06-19 23:06:33 +08:00
|
|
|
|
{
|
|
|
|
|
if (column == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 23:45:48 +08:00
|
|
|
|
column.ColIndex = CurrentColIndex++;
|
2020-06-19 23:06:33 +08:00
|
|
|
|
Columns.Add(column);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 13:39:02 +08:00
|
|
|
|
public void AddHeaderColumn(IColumn column)
|
|
|
|
|
{
|
|
|
|
|
if (column == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 22:36:06 +08:00
|
|
|
|
if (++CurrentColIndex >= Columns.Count)
|
|
|
|
|
{
|
|
|
|
|
CurrentColIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
column.ColIndex = CurrentColIndex;
|
2021-01-11 13:39:02 +08:00
|
|
|
|
HeaderColumns.Add(column);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
public void AddColGroup(IColumn column)
|
|
|
|
|
{
|
|
|
|
|
if (column == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (++CurrentColIndex >= Columns.Count)
|
|
|
|
|
{
|
|
|
|
|
CurrentColIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
column.ColIndex = CurrentColIndex;
|
|
|
|
|
|
|
|
|
|
if (_table.ScrollX != null && Columns.Any(x => x.Width == null))
|
|
|
|
|
{
|
|
|
|
|
var zeroWidthCols = Columns.Where(x => x.Width == null).ToArray();
|
2021-02-14 20:15:53 +08:00
|
|
|
|
var totalWidth = string.Join(" + ", Columns.Where(x => x.Width != null).Select(x => (CssSizeLength)x.Width));
|
2021-01-09 23:57:31 +08:00
|
|
|
|
foreach (var col in Columns.Where(x => x.Width == null))
|
|
|
|
|
{
|
2021-02-14 20:15:53 +08:00
|
|
|
|
col.Width = $"calc(({(CssSizeLength)_table.ScrollX} - ({totalWidth}) + 3px) / {zeroWidthCols.Length})";
|
2021-01-09 23:57:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (column.Width == null)
|
|
|
|
|
{
|
|
|
|
|
var col = Columns.FirstOrDefault(x => x.ColIndex == column.ColIndex);
|
|
|
|
|
if (col != null)
|
|
|
|
|
{
|
|
|
|
|
column.Width = col.Width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
public void AddRowColumn(IColumn column)
|
|
|
|
|
{
|
|
|
|
|
if (column == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (++CurrentColIndex >= Columns.Count)
|
|
|
|
|
{
|
|
|
|
|
CurrentColIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 23:45:48 +08:00
|
|
|
|
column.ColIndex = CurrentColIndex;
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
2021-08-21 01:34:25 +08:00
|
|
|
|
|
|
|
|
|
internal void HeaderColumnInitialed(IColumn column)
|
|
|
|
|
{
|
|
|
|
|
if (column.ColIndex == Columns.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
// Header columns have all been initialized, then we can invoke the first change.
|
2021-09-18 07:48:11 +08:00
|
|
|
|
_table.OnColumnInitialized();
|
2021-08-21 01:34:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|