How to add data to an IEnumerable - Table With related data - MudBlazor

90 Views Asked by At

Simply put I want to add more rows to the table. I have recreated my issue here: https://try.mudblazor.com/snippet/GkQdvvwjdZHabpkB

I also have a textbox which allows the user to apply a filter to the data. E.g. When "Harry" is entered then only rows where the Name contains "Harry" should be returned.

2

There are 2 best solutions below

0
Guilherme Molin On

IEnumerable does not allow record manipulation (add, remove).

You need to change the type from IEnumerable to IList.

0
JonasH On

You can use Concat to produce a new IEnumerable:

people = people.Concat(new []{ new Person()});

However, this is not a great approach if adding many items. You are most likely better of just declaring the the property as a List<T> to make adding items trivial. If needed you can keep an private field with the actual collection type, and a public property that returns a IEnumerable<T>. Also see ImmutableCollections if you want to ensure collections never changes.