Current filter:
                                You should refresh the page.
                                  • Hi,
                                    I am trying to use DxDataGrid on a client side Blazor project. As data I need to use the datatable of an untyped dataset.
                                    As I can understand I should convert the datatable to IEnumetable to use it as data.
                                    But I can't understand how I could set the column field to point to an untyped datacolumn

                                1 Solution

                                Creation Date Importance Sort by

                                Hi,

                                If you know column names of your untyped DataTable, set the Field property of DataGrid's columns to the names of your DataTable columns as constants Field="yourDataTableColumnName".

                                Show all comments
                                • Demertzian 09.03.2019

                                  Hi Paul,
                                  This does not seem to work as on runtime I get  the following error:
                                  WASM: Unhandled exception rendering component: blazor.webassembly.js:1:34844
                                  WASM: System.NullReferenceException: Object reference not set to an instance of an object. blazor.webassembly.js:1:34844
                                  WASM:   at DevExpress.Blazor.Internal.DataBindHelper.GetCellValue[T] (T dataItem, System.String fieldName) <0x346ea08 + 0x0003c> in <d2cea67c0a2a4074b2c0a1da5507cde6>:0

                                  I have created an example showing the issue:

                                  [C#]
                                  @page "/Grid" @using System.Data; @if (GridRows == null) { <p><em>Loading...</em></p> } else { <DxDataGrid Data=@GridRows> <DxDataGridCommandColumn Width="150px"></DxDataGridCommandColumn> PageSize="5" <DxDataGridColumn Field="Col1" Caption="col1" TextAlignment="@DataGridTextAlign.Right"></DxDataGridColumn> <DxDataGridColumn Field="Col2" Caption="col1" TextAlignment="@DataGridTextAlign.Right"></DxDataGridColumn> </DxDataGrid> } @code { private DataSet ds; private IEnumerable<DataRowView> GridRows{ get { foreach(DataRowView dr in ds.Tables[0].DefaultView){ yield return dr; } } } protected override async Task OnInitializedAsync() { PrepareDataset(); } private void PrepareDataset(){ ds=new DataSet(); ds.Tables.Add("test"); ds.Tables[0].Columns.Add("Col1",typeof(string)); ds.Tables[0].Columns.Add("Col2",typeof(string)); var dr=ds.Tables[0].NewRow(); dr["Col1"]="test1"; dr["Col2"]="test2"; ds.Tables[0].Rows.Add(dr); } }
                                • Vova (DevExpress Support) 09.04.2019

                                  Hello,

                                  According to your code, our DataGrid tries to get the "Col1" property of the DataRowView object. I recommend you change the GridRows object type to the list of objects. Please check my sample and let me know if it helps. Please note that I used the object type and you can create your own class (with the Col1 and Col2 properties) for your data source if it's necessary.

                                  Regards,
                                  Vova

                                • Demertzian 09.04.2019

                                  Hi Vova,

                                  Thanks for the explanation. I am afraid I can't use the proposed solution as our project is creating dynamic forms based on metadata and untyped datasets are used as datasources As I can understand untyped DataRowView can't be used directly as datasource. I suppose that DxDatagrid expects the datasource to have  properties or members of the bindable fields.
                                  Is my understanding correct?
                                  Do you plan to support DataRowView as datasource in the future?

                                • Vova (DevExpress Support) 09.04.2019

                                  We are researching a possibility to support the IEnumerable data source in the context of the DataGrid for Blazor - It is not possible to bind the grid to IEnumerable and IEnumerable ticket. However, I cannot provide you with the exact time frame of this research.
                                   
                                  Would you please describe your scenario in greater detail? Do you create your DataGrid based on your metadata?
                                  If it's possible, please modify my sample to illustrate your scenario and send it back to me. I need to understand it better to find the most appropriate solution.
                                  I look forward to your reply.
                                   
                                  Regards,
                                  Vova

                                • Demertzian 09.04.2019

                                  Hi Vova,
                                  It's not trivial to alter your example to match our approach without sending you an extended project. Our project approach is:

                                  1. When a new form is requested the form id is send to the server
                                  2. The server replies with a UITree containing information about the form table and fields.
                                  3. The form uses this information to create an untyped dataset and editors bound to this dataset
                                  So our contraints are that:
                                  4. We don't have predefined models for each form
                                  5. The models are created dynamic
                                  I am attaching a portion of the form to help you understand the main idea
                                  [C#]
                                  @page "/task/{taskID}/{taskKey}" <div> @if (uITree==null) { <p><em>Loading...</em></p> } else { <CascadingValue Value="@modelBaseRow" Name="modelBaseRow"> <CascadingValue Value="crudState" Name="crudState"> <CascadingValue Value="taskDataSet" Name="taskDataSet"> @foreach (var uiElement in uITree.RootElement.Children) { <label>@crudState</label> <LayoutGroup uiElement=@uiElement></LayoutGroup> } </CascadingValue> </CascadingValue> </CascadingValue> } </div> @code { [Parameter] public string? taskID { get; set; } [Parameter] public string? taskKey { get; set; } private TaskDescription? taskDescription; private System.Data.DataSet? taskDataSet; private UIBuilder.UITree? uITree; private System.Data.DataTable? MainTable; private System.Data.DataRow? modelBaseRow; protected override async Task OnInitializedAsync() { taskDescription =await api.GetTaskDescriptionAsync(taskID); uITree=uibuilder.GetUITree(taskDescription); taskDataSet = TaskDescriptionHelper.Instance.CreateTaskDataset(taskDescription); GetMainTable(); if (taskKey != "0") { await doDisplay(taskKey); } else { DoCreate(); }; }
                                • Vova (DevExpress Support) 09.05.2019

                                  Hello Demertzian,
                                   
                                  Thank you for describing your scenario. It seems that the most appropriate approach is to bind our DataGrid to the list of DataRowView objects. However, as I mentioned, our DataGrid doesn't support the IEnumerable  data sources, and we are researching this scenario in the DataGrid for Blazor - It is not possible to bind the grid to IEnumerable and IEnumerable ticket. I recommend you add this ticket to your Favorites to get a notification when we update it. 
                                   
                                  Regards,
                                  Vova

                                • Demertzian 09.09.2019

                                  Hi Vova,
                                  I have made a different approach with list of objects but then I get an error on edit.

                                  Working example with typed list:

                                  [C#]
                                  @page "/Grid" @using System.Data; @if (items == null) { <p><em>Loading...</em></p> } else { <DxDataGrid Data=@items> <DxDataGridCommandColumn Width="150px"></DxDataGridCommandColumn> PageSize="5" <DxDataGridColumn Field="AccountID" Caption="AccountID" TextAlignment="@DataGridTextAlign.Right"></DxDataGridColumn> <DxDataGridColumn Field="Amount" Caption="Amount" TextAlignment="@DataGridTextAlign.Right"></DxDataGridColumn> </DxDataGrid> } @code { List<dataItemClass> items; protected override void OnInitialized() { PrepareDataSource(); } private void PrepareDataSource(){ items=new List<dataItemClass>(); var i=new dataItemClass(); i.AccountID=10; i.Amount=(decimal)500.00; items.Add(i); var j=new dataItemClass(); j.AccountID=20; j.Amount=(decimal)600.00; items.Add(j); } public class dataItemClass{ private decimal? amount; private long? accountID; public decimal? Amount{ get { return amount; } set { amount=value; } } public long? AccountID{ get{ return accountID; } set { accountID=value; } } } }

                                  The same example with List<object>

                                  [C#]
                                  @page "/Grid" @using System.Data; @if (items == null) { <p><em>Loading...</em></p> } else { <DxDataGrid Data=@items> <DxDataGridCommandColumn Width="150px"></DxDataGridCommandColumn> PageSize="5" <DxDataGridColumn Field="AccountID" Caption="AccountID" TextAlignment="@DataGridTextAlign.Right"></DxDataGridColumn> <DxDataGridColumn Field="Amount" Caption="Amount" TextAlignment="@DataGridTextAlign.Right"></DxDataGridColumn> </DxDataGrid> } @code { List<object> items; protected override void OnInitialized() { PrepareDataSource(); } private void PrepareDataSource(){ items=new List<object>(); var i=new dataItemClass(); i.AccountID=10; i.Amount=(decimal)500.00; items.Add(i); var j=new dataItemClass(); j.AccountID=20; j.Amount=(decimal)600.00; items.Add(j); } public class dataItemClass{ private decimal? amount; private long? accountID; public decimal? Amount{ get { return amount; } set { amount=value; } } public long? AccountID{ get{ return accountID; } set { accountID=value; } } } }

                                  throws an exception on edit with the following call stack:

                                  System.InvalidCastException: Object must implement IConvertible.
                                  at System.Convert.ChangeType (System.Object value, System.Type conversionType, System.IFormatProvider provider) <0x33b8b30 + 0x00088> in <ea79d1fd9a764edeb8205d224c78870d>:0
                                  at System.Convert.ChangeType (System.Object value, System.Type conversionType) <0x33b8070 + 0x0000c> in <ea79d1fd9a764edeb8205d224c78870d>:0
                                  at DevExpress.Blazor.Base.DxDataGridBase`1[T].ConvertDataItem (System.Object dataItem) <0x33b8028 + 0x00008> in <d2cea67c0a2a4074b2c0a1da5507cde6>:0
                                   at DevExpress.Blazor.Base.DxDataGridBase`1[T].DevExpress.Blazor.Grid.Internal.IDataGridColumnOwner.RowEditStart (System.Object dataItem) <0x33b7f18 + 0x00006> in <d2cea67c0a2a4074b2c0a1da5507cde6>:0

                                • Vova (DevExpress Support) 09.10.2019

                                  Hello,

                                  Thank you for your code snippets. I reproduced this behavior. We will research it in the context of the T813820: DataGrid for Blazor - The "Object must implement IConvertible" error occurs when DxDataGrid is bound to the List and the editing is initiated  ticket. I recommend you add this ticket to your Favorites to get a notification when we update it. 

                                  Regards,
                                  Vova

                                • Vova (DevExpress Support) 09.20.2019

                                  Hello,
                                   
                                  I would like to note that starting from the 0.4.0 version, our Data Grid for Blazor supports binding to the IEnumerable collection of the ExpandoObject objects. This feature can be helpful in your scenario with the dynamic DataTable object.
                                  Please check the Blazor Data Grid - How to bind a grid to a DataTable object example and let me know if this information is helpful.
                                   
                                  Regards,
                                  Vova

                                • Demertzian 09.20.2019

                                  Hi Vova,
                                  Thanks, this really simplifies my project.
                                  For the moment I had created  wrapper object for the rows using IL which worked but is quite complex

                                • Vova (DevExpress Support) 09.23.2019

                                  You are welcome!