Columns configuration.

my grid plugin is :

@Html.EJS().Grid("FlatGrid").DataSource((System.Data.DataTable)ViewBag.DataSource).EnableVirtualization().AllowResizing(true).Height("100%").Width("100%").AllowFiltering().AllowSorting().AllowSelection().FilterSettings(filter =>
{ filter.Type(Syncfusion.EJ2.Grids.FilterType.Excel); }).ToolbarClick("toolbarClick").Toolbar(toolbarItems).Columns(ViewBag.cols).Render()

when i delete Columns propertie my grid works but when i add Columns(ViewBag.cols) i will have a correct headers but white rows (no data).

1 Reply

RU Ramdhas  Ueikattan Syncfusion Team June 18, 2018 01:06 PM UTC

Hi Bassem, 

Thanks for your interest in Syncfusion products. 

We have validated your query and the grid data will be render based on the “Field” property of the column. The HeaderText in column used for showing column’s header. We suspect you are not defined correct “Field” value for column and please refer the below code examples. 

Razor Code:  

@Html.EJS().Grid("Grid").DataSource((IEnumerable<Object>)ViewBag.DataSource).Columns((Syncfusion.EJ2.Grids.GridColumn[])ViewBag.Column).AllowPaging().AllowSorting().PageSettings(p=>p.PageSize(5)).Render() 



Controller Code:  

            var columns = new Syncfusion.EJ2.Grids.GridColumn[3]; 
            columns[0] = new Syncfusion.EJ2.Grids.GridColumn { Field = "OrderID", HeaderText = "Order ID", Width = "100" }; 
            columns[1] = new Syncfusion.EJ2.Grids.GridColumn { Field = "CustomerID", HeaderText = "Customer ID", Width = "100" }; 
            columns[2] = new Syncfusion.EJ2.Grids.GridColumn { Field = "Freight", HeaderText = "Freight", Width = "100", Format="C2" }; 
            ViewBag.Column = columns; 
            ViewBag.DataSource = OrdersDetails.GetAllRecords();  


For your reference, we have created a simple sample based on your requirement that can be downloaded from the below location  

 
Please let us know, if you need any further assist on this. 

Regards, 
Ramdhas  Ueikattan 


Loader.
Up arrow icon