Bind GridColumn field to indexed element
Hi,
With the Blazor EjsGrid control is it possible to bind a GridColumn to an indexed value like you can with the WPF version?
e.g.
<GridColumn Field="Values[0]" HeaderText="Values[0]" />
Thanks, John
SIGN IN To post a reply.
9 Replies
VN
Vignesh Natarajan
Syncfusion Team
September 23, 2019 06:48 AM UTC
Hi John,
Greetings from Syncfusion support.
Query: “With the Blazor EjsGrid control is it possible to bind a GridColumn to an indexed value”
Yes. We can render the GridColumns by dynamically building them based on the list of strings. We have already documented this topic in our UG documentation which can be referred below
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan.
JO
John
September 24, 2019 06:51 AM UTC
Thank you for the response, but it does not explain how/whether it is possible to bind to indexed values (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/). I know you support this in the WPF version (https://help.syncfusion.com/wpf/datagrid/data-binding#binding-indexer-properties)
Thanks, John
VN
Vignesh Natarajan
Syncfusion Team
September 25, 2019 12:14 PM UTC
Query: “but it does not explain how/whether it is possible to bind to indexed values”
We have prepared a sample as per your requirement (to render Grid columns based on index value of an array). Kindly refer the below code example.
|
<EjsGrid DataSource"@OrderData">
<GridColumns>
@for (var I = 0; I < Cols.Length; I++)
{
<GridColumn Field="@Cols[I]" IsPrimaryKey="@(Cols[I] == "OrderID")" HeaderText="@Header[I]"></GridColumn>
}
</GridColumns>
</EjsGrid>
@code{
public string[] Cols = { "OrderID", "CustomerID", "EmployeeID" };
public string[] Header = { "ID", "Name", "Batch ID" }; |
Refer the below screenshot for the output
|
|
Also download the sample from below
Kindly confirm whether above solution satisfy your requirement. If not share more details about your requirment along with the index value properties.
Regards,
Vignesh Natarajan.
JO
John
September 26, 2019 06:42 AM UTC
Thank you for the response, but it is not the headers or fixed fields I am worried about, but binding to indexed values. I have included an example below, but please also see the link to the same functionality in your WPF version at (https://help.syncfusion.com/wpf/datagrid/data-binding#binding-indexer-properties). Thank you
@page "/"
@using Syncfusion.EJ2.Blazor.Grids
@code {
private List rows = new List() { new Row() };
private class RowValues : IList
{
public double this[int index]
{
get
{
return ...;
}
}
...
}
private class Row
{
public RowValues RowValues { get; } = new RowValues();
}
}
VN
Vignesh Natarajan
Syncfusion Team
September 27, 2019 12:28 PM UTC
Hi John,
Sorry for the inconvenience caused.
Query: “but it is not the headers or fixed fields I am worried about, but binding to indexed values.”
We do not have support to bind the indexer property values to EjsGrid. But you can achieve your requirement (to display data based on Indexer values) using Column Template feature of EjsGrid. However we will not be able to perform Data Operations like filtering, sorting, CRUD etc in Grid.
Refer the below code example
|
<EjsGrid ModelType="@RowValue[0]" DataSource="@RowValue">
<GridColumns>
<GridColumn HeaderText="Names">
<Template>
@{
var index = (context as RowValues)[0];
<span>@index</span>
}
</Template>
</GridColumn>
</GridColumns>
</EjsGrid>
@code{
public class RowValues
{
private List<string> rows = new List<string>() { "VINET" };
public string this[int index]
{
get
{
return rows[index];
}
}
public int ID { get; set; }
}
public List<RowValues> RowValue = new List<RowValues>()
{
new RowValues(){ ID = 1 }
};
} |
For your reference we have prepared a sample which can be downloaded from below link
Refer our UG documentation for your reference
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan.
JO
John
October 1, 2019 05:16 PM UTC
Thank you for the response, but we need the ability to sort, filter & group.
1. Is this something you are likely to support soon?
2. In the absence of this, is there any other way to bind the grid to elements that are not known at compile time? e.g. DataTable, dynamic object, implementing some interface etc..
In 50% of our uses of grid, we do not have a fixed class to bind to at compile time. I can't image this is an unusual request, and you support various mechanisms in your WPF version.
Regards, John
VN
Vignesh Natarajan
Syncfusion Team
November 5, 2019 10:07 AM UTC
Hi John,
Query: “In the absence of this, is there any other way to bind the grid to elements that are not known at compile time?”
As mentioned in the previous update, we are not able to perform data operation while binding the data using indexer property or using ExpandoObject / anonymous object. But we would like to inform you that, we have considered this (data operations using ExpandoObject / dynamic object) requirement as feature and it will be included in any of our upcoming release.
You can track the status of these features using the below feedback links,
Feedback: https://www.syncfusion.com/feedback/6878/need-crud-operation-support-for-anonymous-type-binding
Till then we appreciate your patience.
Regards,
Vignesh Natarajan.
PD
Peter Drier
January 20, 2023 03:32 PM UTC
3+ years later, is it yet possible to properly access the index operator?
Specifically from John's September 26, 2019 message above? Cheers, Peter
MS
Monisha Saravanan
Syncfusion Team
January 26, 2023 02:42 PM UTC
Hi Peter,
We would like to inform that we don’t have support for indexer property in Blazor DataGrid. Please let us know if you have any concerns.
SIGN IN To post a reply.
- 9 Replies
- 4 Participants
-
JO John
- Sep 21, 2019 04:54 PM UTC
- Jan 26, 2023 02:42 PM UTC