☀️ Table 新增 FilterRealTime

This commit is contained in:
Tom
2026-01-08 18:05:35 +08:00
parent 38cbb10b4f
commit 19d8add20c
4 changed files with 55 additions and 24 deletions

View File

@@ -25,6 +25,7 @@ namespace AntdUI
#region Ctor
IList<object>? CustomSource;
bool realTime = false;
public FilterControl(Table table, System.Drawing.Font font, Column currentColumn, IList<object>? customSource)
{
InitializeComponent();
@@ -32,6 +33,7 @@ namespace AntdUI
_table = table;
_column = currentColumn;
CustomSource = customSource;
realTime = table.FilterRealTime;
dv.VirtualMode = table.VirtualMode;
dv.Columns = new ColumnCollection { new ColumnCheck("check"), new Column("text", "(全选)").SetLocalizationTitle("Filter.SelectAll") };
if (Option.Table == null) Option.Table = table;
@@ -138,8 +140,7 @@ namespace AntdUI
var edit = new Input
{
Margin = new Padding(0),
Dock = DockStyle.Fill,
Text = Option.FilterValues != null && Option.FilterValues.Count == 1 && Option.FilterValues[0] != DBNull.Value ? Option.FilterValues[0]?.ToString() ?? string.Empty : string.Empty
Dock = DockStyle.Fill
};
tablePanel.Controls.Add(edit, 1, 0);
edit.TextChanged += Edit_TextChanged;
@@ -282,7 +283,6 @@ namespace AntdUI
object[]? cc;
void Search()
{
count++;
var search = inputSearch.Text;
if (dv.Tag is List<AntItem[]> list)
{
@@ -322,6 +322,7 @@ namespace AntdUI
dv.DataSource = nl;
}
}
Apply();
}
}
void Search(object[]? value)
@@ -355,6 +356,8 @@ namespace AntdUI
else return FilterCondition(condition, val, value);
}
#region
public static bool FilterCondition(FilterConditions condition, object? val, object? value)
{
// 处理双方为null的情况
@@ -495,6 +498,8 @@ namespace AntdUI
#endregion
#endregion
private void SelectCondition_Changed(object sender, ObjectNEventArgs e)
{
if (e.Value is FilterConditions condition)
@@ -579,6 +584,28 @@ namespace AntdUI
}
}
private void dv_CheckedChanged(object sender, TableCheckEventArgs e) => count++;
void Apply()
{
count++;
if (realTime)
{
if (_table.dataTmp == null) return;
if (dv.DataSource is List<AntItem[]> list)
{
var tmp = new List<object?>(list.Count);
foreach (var it in list)
{
if (it[1].value is bool check && check && it[0].value is List<object> data) tmp.AddRange(data);
}
if (tmp.Count == _table.dataTmp.RowsCache.Length) Option.FilterValues = null;
else Option.FilterValues = tmp;
Option.UpdateFilter();
LoadOffset();
btn_clean.Enabled = Option.Enabled;
}
}
}
private void dv_CheckedChanged(object sender, TableCheckEventArgs e) => Apply();
}
}

View File

@@ -214,7 +214,7 @@ namespace AntdUI
/// <summary>
/// 是否已启用筛选
/// </summary>
public bool Enabled => FilterValues != null && FilterValues.Count > 0;
public bool Enabled => FilterValues != null;
/// <summary>
/// 列数据类型 (默认string)

View File

@@ -460,30 +460,28 @@ namespace AntdUI
}
else if (it.row.IsColumn && it.cell is TCellColumn col)
{
if (it.cell.COLUMN.Filter != null)
if (it.cell.COLUMN.Filter != null&& col.rect_filter.Contains(db.x - col.offsetx, db.y - col.offsety))
{
if (col.rect_filter.Contains(db.x - col.offsetx, db.y - col.offsety))
//点击筛选
var focusColumn = it.cell.COLUMN;
if (OnFilterPopupBegin(focusColumn, out var customSource, out var fnt, out var filterHeight))
{
//点击筛选
var focusColumn = it.cell.COLUMN;
if (OnFilterPopupBegin(focusColumn, out var customSource, out var fnt, out var filterHeight))
fnt ??= Font;
var editor = new FilterControl(this, fnt, focusColumn, customSource);
if (filterHeight.HasValue) editor.Height = filterHeight.Value;
editor.Set(new Popover.Config(this, editor)
{
fnt ??= Font;
var editor = new FilterControl(this, fnt, focusColumn, customSource);
if (filterHeight.HasValue) editor.Height = filterHeight.Value;
editor.Set(new Popover.Config(this, editor)
{
Dpi = (fnt.Size / 10F) * Dpi,
Tag = focusColumn.Filter,
ArrowAlign = TAlign.Bottom,
Font = fnt,
Offset = col.rect_filter,
Padding = new Size(6, 6)
}.open());
}
Dpi = (fnt.Size / 10F) * Dpi,
Tag = focusColumn.Filter,
ArrowAlign = TAlign.Bottom,
Font = fnt,
Offset = col.rect_filter,
Padding = new Size(6, 6)
}.open());
}
return;
}
else if (it.cell.COLUMN.SortOrder)
if (it.cell.COLUMN.SortOrder)
{
//点击排序
SortMode sortMode = SortMode.NONE;

View File

@@ -904,6 +904,12 @@ namespace AntdUI
[Description("省略文字提示"), Category("行为"), DefaultValue(true)]
public bool ShowTip { get; set; } = true;
/// <summary>
/// 筛选实时生效
/// </summary>
[Description("筛选实时生效"), Category("行为"), DefaultValue(false)]
public bool FilterRealTime { get; set; }
/// <summary>
/// 超出文字提示配置
/// </summary>