<ejs-grid id="Grid" dataSource="ViewBag.DataSource" height="273" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100" validationRules="@(new{ required: true })"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120" validationRules="@(new { required: true, minLength: [customFn, 'Need atleast 5 letters'] })></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
I would like to be able to generate these columns automatically from data annotations.
I've seen other forum posts about using the @Html.EJ() and/or @Html.EJS() extensions to create the grid, but I have no idea
where these extensions live. I've tried installing the Syncfusion.EJ2.MVC5 package, but it breaks my project (tag helpers are no longer recognized).
... namespace TestSample.Controllers { public class HomeController : Controller { public IActionResult Index() { ViewBag.DataSource = OrdersDetails.GetAllRecords().ToList(); ViewData["columns"] = new List { new Syncfusion.EJ2.Grids.GridColumn() { Field = "OrderID", HeaderText = "Order ID", Width = "120", IsPrimaryKey = true }, new Syncfusion.EJ2.Grids.GridColumn() { Field = "CustomerID", HeaderText = "Customer ID", Width = "120", EditType="dropdownedit" }, new Syncfusion.EJ2.Grids.GridColumn() { Field = "ShipCity", HeaderText = "Ship City", Width = "120"}, new Syncfusion.EJ2.Grids.GridColumn() { Field = "ShipCountry", HeaderText = "Ship Country", Width = "120" } }; return View(); } } public class OrdersDetails { public static List List ... } |
<div> <ejs-grid id="Grid" dataSource="ViewBag.DataSource" allowResizing="true" allowPaging="true" columns="@ViewData["columns"]" allowSorting="true" toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Cancel", "Update"})"> <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog">e-grid-editSettings> ejs-grid> div> |