@@ -6993,6 +6993,12 @@ public void ExportAsync_Ok()
69936993 builder . AddAttribute ( 1 , "Field" , "Name" ) ;
69946994 builder . AddAttribute ( 2 , "FieldExpression" , Utility . GenerateValueExpression ( foo , "Name" , typeof ( string ) ) ) ;
69956995 builder . CloseComponent ( ) ;
6996+
6997+ builder . OpenComponent < TableColumn < Foo , string > > ( 0 ) ;
6998+ builder . AddAttribute ( 1 , "Field" , "Address" ) ;
6999+ builder . AddAttribute ( 2 , "FieldExpression" , Utility . GenerateValueExpression ( foo , "Address" , typeof ( string ) ) ) ;
7000+ builder . AddAttribute ( 3 , "IgnoreWhenExport" , true ) ;
7001+ builder . CloseComponent ( ) ;
69967002 } ) ;
69977003 } ) ;
69987004 } ) ;
@@ -7007,9 +7013,20 @@ public void ExportAsync_Ok()
70077013 }
70087014
70097015 var table = cut . FindComponent < Table < Foo > > ( ) ;
7016+
7017+ // 可见列为 2 列
7018+ var columns = table . Instance . GetVisibleColumns ( ) ;
7019+ Assert . Equal ( 2 , columns . Count ( ) ) ;
7020+
7021+ // 由于设置了 IgnoreWhenExport 为 true 所以导出时不包含 Address 列
7022+ ITableExportDataContext < Foo > ? exportContext = null ;
70107023 table . SetParametersAndRender ( pb =>
70117024 {
7012- pb . Add ( a => a . OnExportAsync , _ => Task . FromResult ( true ) ) ;
7025+ pb . Add ( a => a . OnExportAsync , context =>
7026+ {
7027+ exportContext ??= context ;
7028+ return Task . FromResult ( true ) ;
7029+ } ) ;
70137030 } ) ;
70147031
70157032 buttons = cut . FindAll ( ".dropdown-menu-end .dropdown-item" ) ;
@@ -7020,6 +7037,9 @@ public void ExportAsync_Ok()
70207037 button . Click ( ) ;
70217038 } ) ;
70227039 }
7040+ Assert . NotNull ( exportContext ) ;
7041+ Assert . Single ( exportContext . Columns ) ;
7042+ Assert . Equal ( "Name" , exportContext . Columns . ElementAt ( 0 ) . GetFieldName ( ) ) ;
70237043 }
70247044
70257045 [ Fact ]
@@ -8208,37 +8228,6 @@ public void IsMarkupString_Ok()
82088228 Assert . Equal ( "<div class=\" table-cell\" ><div>Address - Test</div></div>" , cells [ 1 ] . InnerHtml ) ;
82098229 }
82108230
8211- [ Fact ]
8212- public void IgnoreWhenExport_Ok ( )
8213- {
8214- var items = new Foo [ ] { new ( ) { Name = "Name" , Address = "Address" } } ;
8215- var cut = Context . RenderComponent < BootstrapBlazorRoot > ( pb =>
8216- {
8217- pb . AddChildContent < Table < Foo > > ( pb =>
8218- {
8219- pb . Add ( a => a . RenderMode , TableRenderMode . Table ) ;
8220- pb . Add ( a => a . Items , items ) ;
8221- pb . Add ( a => a . TableColumns , foo => builder =>
8222- {
8223- builder . OpenComponent < TableColumn < Foo , string > > ( 0 ) ;
8224- builder . AddAttribute ( 1 , "Field" , "Name" ) ;
8225- builder . AddAttribute ( 2 , "FieldExpression" , Utility . GenerateValueExpression ( foo , "Name" , typeof ( string ) ) ) ;
8226- builder . CloseComponent ( ) ;
8227-
8228- builder . OpenComponent < TableColumn < Foo , string > > ( 0 ) ;
8229- builder . AddAttribute ( 1 , "Field" , "Address" ) ;
8230- builder . AddAttribute ( 2 , "FieldExpression" , Utility . GenerateValueExpression ( foo , "Address" , typeof ( string ) ) ) ;
8231- builder . AddAttribute ( 3 , "IgnoreWhenExport" , true ) ;
8232- builder . CloseComponent ( ) ;
8233- } ) ;
8234- } ) ;
8235- } ) ;
8236-
8237- var table = cut . FindComponent < Table < Foo > > ( ) ;
8238- var columns = table . Instance . GetVisibleColumns ( ) ;
8239- Assert . Single ( columns ) ;
8240- }
8241-
82428231 [ Fact ]
82438232 public void OnSelectedRows_Ok ( )
82448233 {
0 commit comments