Use object[][] dataset
Hi,
I want to upload a CSV and display it in a grid.
I don't know column name in advantce.
If I have
List<string> columns
and
List<List<string>> rows
how can I display it in with a Blazor Grid component ?
Thanks
SIGN IN To post a reply.
3 Replies
VN
Vignesh Natarajan
Syncfusion Team
May 27, 2020 12:01 PM UTC
Hi Thomas,
Greetings from Syncfusion support.
Query: “I want to upload a CSV and display it in a grid I don't know column name in advantce. List<string> columns”
As per your requirement we have prepared a sample to render Grid with dynamic columns based on csv file. Kindly download the sample from below
Refer the below code example for your reference
|
<SfGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true">
<GridColumns>
@foreach (var prop in ColumnNames)
{
<GridColumn Field="@prop" IsPrimaryKey="@(prop == "OrderID")"></GridColumn>
}
</GridColumns>
</SfGrid>
|
Refer our UG documentation for your reference
Regards,
Vignesh Natarajan
RT
Rémi THOMAS
May 27, 2020 02:56 PM UTC
Thanks Vignesh
I adapted it like this, completly neutral on column names
ColumnNames = (from dc in dt.Columns.Cast<DataColumn>()
select dc.ColumnName).ToList<string>();
foreach (DataRow row in dt.Rows)
{
ExpandoObject x = new ExpandoObject();
var y = x as IDictionary<string, Object>;
for (int i=0; i<ColumnNames.Count; i++)
y.Add(ColumnNames[i], row[i].ToString());
Orders.Add(x);
}
VN
Vignesh Natarajan
Syncfusion Team
May 28, 2020 05:06 AM UTC
Hi Rémi,
Thanks for your suggestion.
We are glad to hear that you have achieve your requirement using our solution.
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
RT Rémi THOMAS
- May 26, 2020 07:54 PM UTC
- May 28, 2020 05:06 AM UTC