@(Html.EJ().Grid<T_PRODUCT>("RemoteBinding")
.Datasource(ds => ds.URL(url).UpdateURL(url).InsertURL(url).RemoveURL(url))
.EditSettings(edit =>
{
edit.AllowAdding()
.AllowDeleting()
.AllowEditing()
.EditMode(EditMode.ExternalFormTemplate).ExternalFormTemplateID("#templateEditing");
})
.EnableAltRow()
.AllowPaging()
.AllowResizing()
.AllowSorting()
.AllowMultiSorting()
.AllowGrouping()
.AllowFiltering()
.FilterSettings(filter =>
{
filter.FilterType(FilterType.Menu);
})
.ClientSideEvents(eve => { eve.ActionComplete("actionComplete"); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
items.AddTool(ToolBarItems.PrintGrid);
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.WordExport);
items.AddTool(ToolBarItems.PdfExport);
});
})
.Columns(col =>
{
col.Field("id").HeaderText("ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(20).Add();
col.Field("title").HeaderText("Title").EditType(EditingType.String).Width(190).Add();
col.Field("image").HeaderText("Image").EditType(EditingType.String).Width(190).Add();
col.Field("enable").HeaderText("Is enable").EditType(EditingType.Boolean).Width(30).Add();
col.Field("place_order").HeaderText("Order").EditType(EditingType.Numeric).Width(20).Add();
col.Field("point").HeaderText("point").EditType(EditingType.Numeric).Width(20).Add();
})
)
Some image :
Doesn't work with grid
but work with browser ???
and if i use javascript grid, i have the same problem except for when i use some query :-(
//THIS WORK
var dataManager2 = ej.DataManager("/api-v1.0/Product/");
var queryCustomer2 = ej.Query().select("id", "title", "point", "image", "enable");
$("#test2").ejGrid({
dataSource: dataManager2,
query: queryCustomer2,
columns: ["id", "title", "point", "image", "enable"]
});
//BUT THIS DOESN'T WORK ...
var dataManager3 = ej.DataManager("/api-v1.0/Product/");
var queryCustomer2 = ej.Query().select("id", "title", "point", "image", "enable");
$("#test3").ejGrid({
dataSource: dataManager3,
columns: ["id", "title", "point", "image", "enable"]
});
Thank's for all reply :-)
var dataManager2 = ej.DataManager("/api-v1.0/Product/"); var queryCustomer2 = ej.Query().select("id", "title", "point", "image", "enable"); $("#test2").ejGrid({ dataSource: dataManager2, query: queryCustomer2, columns: ["id", "title", "point", "image", "enable"] |
// GET: odata/Product(5)/TJ_PRODUCT_SALL
[EnableQuery]
public IQueryable<TJ_PRODUCT_SALL> GetTJ_PRODUCT_SALL([FromODataUri] short key)
{
return db.T_PRODUCT.Where(m => m.id == key).SelectMany(m => m.TJ_PRODUCT_SALL);
}
.EnableCaching().CachingPageSize(10).TimeTillExpiration(10)
Hi Philippe,
From the provided code, we found that the reported issue is due to circular reference. While serializing the relational data, the circular reference error will occur due to the repetition of class.
We can resolve the issue using “ViewModel” concept as follows,
public class ProductController : ODataController { private DatabaseSampleEntities db = new DatabaseSampleEntities();
// GET: odata/Product [EnableQuery] public IQueryable<ProductsViewModel> GetProduct() { var data= db.T_PRODUCT.Select(d => new ProductsViewModel { id = d.id, enable=d.enable, image=d.image, place_order=d.place_order, point= d.point, title=d.title }).AsQueryable();
return data; public class ProductsViewModel { public short id { get; set; } public string title { get; set; } public Nullable<byte> point { get; set; } public string image { get; set; } public bool enable { get; set; } public byte place_order { get; set; } |
As in the above code example, we can access the fields that are needed to bind to the Grid alone.
While using above code example, register the ViewModel to the WebApiConfig.cs class as follows,
public static class WebApiConfig { public static void Register(HttpConfiguration config) builder.EntitySet<SyncfusionHelp.Areas.ApiOdata.Controllers.ProductController.ProductsViewModel>("ProductsViewModel"); config.Routes.MapODataServiceRoute("odata", "api-v1.0", builder.GetEdmModel()); } |