Comments (17)
Thanks for contacting us @Jason190 , could you please post your code here to reproduce?
from ant-design-blazor.
Hi, @ElderJames . Thx for your reply.
<Table TItem="TableData" DataSource="@ServiceTableData.Datas" [email protected] ScrollY="412px" EnableVirtualization HidePagination>
<GenerateColumns Range="1.." Definitions=definitions />
<ActionColumn Title="Action">
<Space Size=@("middle")>
<SpaceItem>
<a>Invite @context.ID</a>
</SpaceItem>
</Space>
</ActionColumn>
</Table>
As you see. I bind the DataSource to Datas which belong to ServiceTableData.
public class ServiceTableData : IServiceTableData
{
public TableData[]? Datas { get; set; }
public event Action<TableData[]> OnChange;
public void Update(TableData[] datas)
{
Datas = datas;
OnChange?.Invoke(datas);
}
}
This is ServiceTableData class above.
foreach (double[] item in objArray)
{
TableData oneline = new TableData()
{
Key = keyNum++.ToString(),
ID = item[0].ToString(),
ObjectID = item[1].ToString(),
Area_size = item[2]
};
datas = datas.Concat(new TableData[] {oneline}).ToArray();
}
ServiceTableData.Update(datas);
This is in another class which is actual assignment to DataSource. Perhaps I'm missing some conceptual details, please let me know.
Thanks a lot.
from ant-design-blazor.
@Jason190 Are you using Interactive rendering? By the way, you can generate columns with for loop and PropertyColumn, for example, I used it for my dynamic schedule table:
` @for (int i = 0; i < _weeks; i++)
{
var weekIndex = i + _startWeek;
var title = $"Week {weekIndex}";
var weekDays = i == 0 ? _firstWeekDays : i == _weeks - 1 ? _lastWeekDays : 7;
var width = weekDays * 15;
var index = i;
@{
if (context.weekDataList.Length != _weeks)
{
index = -1;
}
var week = index >= 0 ? context.weekDataList[index] : new WeekData();
var segments = week.segments;
}
<ScheduleFragment Segments="@segments"/>
</PropertyColumn>
}`
comparing length is actually required because it re renders with previous context and new data (it updates data, rerenders and only then updates column definitions then rerenders again and so we need to not access data before new column definition re-render) and causes index out of bounds.
from ant-design-blazor.
@GoldSucc Thank you for your enthusiastic reply!
I do actually want to make changes to the data in the table while the program is running.
I didn't find anything in the example program about that part, though. So I'm guessing that assigning values directly to the binding value would work.
from ant-design-blazor.
@Jason190 yes, I would recommend to assign a new list/array to datasource each time something changes, for example I do this:
in table _entries is an array of schedule entries and when user requests schedule for a new date range, I recalculate schedule and do this: _entries = scheduleEntries; where scheduleEntries is a new array of entries. for better performance I recommend to use struct instead of classes and array instead of a list, it will be more memory efficient and fasterfrom ant-design-blazor.
@GoldSucc Hi,
Do you means that the could not re-render in program running? It seems make sense.
from ant-design-blazor.
@Jason190 column definitions are render fragment and after you change data source it will try to render new data with outdated render fragment and only then it will recalculate render fragment of columns, which may cause errors, at least it happened for me. because I render week schedule, it can cause index out of bound if new date range contains more weeks than a previous one, so I check if that's the case. may be it can be fixed by overriding should re-render method and prevent re-rendering before full state update, but for me simpler solution is to check if new column render fragment have same column count as a required week count
from ant-design-blazor.
from ant-design-blazor.
@Jason190 by the way, to enable re-rendering of the table, you should enable InteractiveServer, InteractiveWebAssembly or InteractiveAuto render modes, it looks like table is not working properly when statically rendered. For static rendering I would recommend to use good old html table instead of ant component
from ant-design-blazor.
Getting the instance of the table via the ref method, I find that the datasource is empty in the instance. But I have just assigned the value. Why is this?
from ant-design-blazor.
@Jason190 Can you share your code? It may depend on lifecycle usage. Which render mode are you using?
from ant-design-blazor.
@Jason190 also most of the times you don't have to use ref to assign, you can bind value by using <Table DataSource="_myList"
have you checked that value you are assigning is not null?
from ant-design-blazor.
@GoldSucc I'm completely dizzy already. Could you write an example of this part for me?
from ant-design-blazor.
@Jason190 can create complete example for you after work day. busy for now. also you can send me your code and may be I will be able to help you fixing
from ant-design-blazor.
@GoldSucc Would you tell me your email address?
from ant-design-blazor.
@Jason190 [email protected], [email protected]
from ant-design-blazor.
Hello @Jason190 @GoldSucc , have you solved the issue?
from ant-design-blazor.
Related Issues (20)
- DisabledDate Disable the same year when its available HOT 3
- Can it be used in webview2? HOT 2
- Seems a bug in Dictionary Support in Form HOT 5
- Issue of InputNumber component HOT 2
- Table Select HOT 3
- Theme using InteractiveAuto HOT 4
- The type 'IsExternalInit' exists in both AntDesign and System.Runtime HOT 1
- Will the TreeTransfer component be implemented in the future? HOT 1
- Antblazer Pro always jumps to the homepage
- Please suspend support for.NET versions below 7.0 HOT 1
- The treeselect component AllowClear is invalid HOT 1
- NullReferenceException in FormItem 0.18.2 HOT 7
- As long as in the asynchronous code, _table. ReloadData(); Why doesn't it take effect? HOT 10
- AutoFocus by Select
- Table component: When the column is fixed on the left, the column is not the first, and the position is fixed incorrectly HOT 1
- Multilingual localization of form validation HOT 2
- AutoComplete do not show options panel when loading page HOT 1
- There is a bug between the layout and the tab HOT 2
- Extreme CPU usage by Ant-Blazor Select-Component HOT 3
- Exception occurs when clicking clear button of TreeSelect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ant-design-blazor.