Hi,
I am having issues with the autogeneratecolumns feature of igGrid.
I am given the task of making a generic grid which could render the data of a dynamic datasource provided to it at runtime.
I am using Asp.Net MVC. I have a view named Listing.cshtml which will get an action method and cotroller name in its ViewBag and render the grid with datasourceurl set as the ViewBag.ActionMethod & ViewBag,ControllerName supplied to it.
This means that the grid will be displaying dynamic data and its datasource will change dynamically, because GridDataSource action name will be passed as a parameter.
When I set autogeneratecolumns(true) my grid does not render the rows and instead shows a loading circle animation which keeps on loading. I was just checking to see if my grid would render the columns automatically or not, because if I specify the columns explicitly the grid renders fine. When i set autogeneratecolumns to true, the grid does not display data.
Why is that happening? Please guide me i am stuck here. How can I render the grid dynamically without knowing the columns of the datasource through Asp.Net MVC helper.
Also is this achievable that I have a single .cshtml page for my grid and at runtime the page is supplied with the DataSourceUrl, and after reading it from the ViewBag , The grid loads its datasource at runtime. Is this possible? If it is then what would I provide inside the @(Html.Infragistics().Grid<????>() ??
And would the grid render without specifying the @model directive on top of page because the model will change at runtime.
Please help me out here , and if possible please provide a working sample in which the grid datasource is loaded dynamically and its datasource is set to a string which contains the name of [GridDataSourceAction].
Also why my grid is no displaying data when i set autogeneratecolumns to true and renders fine when I explicitly specify the columns.
Any help would be appreciated.
Hello led zeppelin,
After investigating this matter further and discussing it with our developers I believe the reason for this issue is that AutoGenerateColumns property is not recommended to be used with dataSourceUrl property. AutoGenerateColumns(true) in MVC expects data source to be available in initialization time, because it implicitly generates columns definitions and sets AutoGenerateColumns(false). This is done on purpose in order to support other basic scenarios. When DataSourceUrl is used and you didn't provide data source explicitly the data source is not available at initialization time, thus the grid generates a JavaScript error on the client side in browser error console (as you may notice with the sample project attached)
Additionally, in order to change your model dynamically you should initialize the grid using Java Script instead of using MVC chaining initialization.
Regarding your remote paging scenario what I can suggest is explicitly setting the pageIndexUrlKey and pageSizerUrlKey. By design, if they are not set the grid will make an oData query to retrieve values for them. The configuration of your grid should be similar to the following:
$('#grid1').igGrid({ dataSource: "/Home/GetData", // your data should be retrieved here autoGenerateColumns: true, features: [ { recordCountKey: 'TotalRecordsCount', pageIndexUrlKey: 'page', pageSizeUrlKey: 'pageSize', name: 'Paging' } ]
I am attaching a sample project for your reference. In this application there are two igGrids – one created using MVC Helper, which is not loading the data correctly and one created using Java Script, which is working as expected.
I hope you find this information helpful, please let me know if you need any additional information regarding this matter.
PS: I have read the replies in this thread http://ko.infragistics.com/community/forums/p/79298/400741.aspx#400741
But i am unable to achieve what i wanted. Please provide a short working sample if you can of autogeneratecolumns(true) using MVC Helper where all the settings are set in action method of controller rather than the ViewPages.
Okay , I am waiting for your response.
Please provide a short working sample of igGrid using ASP.Net MVC Helper where autogenerate columns is set to true. Because I have searched alot about this and I think the problem is that the grid is not getting the GridDataSource to render the columns when autogeneratecolumns is set to true.
Heres my Users/GetUsers action method :
/// <summary> Datasource for infragistics grid </summary> //[GridDataSourceAction] [ActionName("GetUsers")] public ActionResult GetUsers() { var pageSize = HttpUtility.ParseQueryString(Request.Url.Query).Get("pageSize"); var pageIndex = HttpUtility.ParseQueryString(Request.Url.Query).Get("page"); Entity entity = new Entity { Name = "User", Action = "Select" }; UserViewModel userViewModel = new UserViewModel(); //userViewModel.Records = c21HttpClient.GetAllEntities<User>(entity, "10", "0").AsQueryable(); userViewModel.ResponseCountKey = 10; JsonResult jsonResult = new JsonResult(); jsonResult.Data = userViewModel; jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return jsonResult; }
Thank you for posting in our community.
I am currently looking into this matter for you and I am discussing the issue with our senior staff. I will keep you posted on my progress and I will get back to you as soon as I have any new information for you.
Please do not hesitate to contact me if you have any further questions.
The grid works fine when i specify the columns explicitly.
My action method Users/GetUsers returns Json data.
When i used Jquery to implement autogeneratecolumns(true) , the grid rendered the data but i could not get the pageSize & pageIndex properties in my GridDataSource Action method. When i use MVC Helper , i get the pageSize PageIndex parameters but autogeneratecolumns does not work. Please help me out here.
This is the code which I wrote to render the grid using MVC Helper. But the grid just shows loading circle animation and does not get data.
@{ ViewBag.Title = "UsersListing";}<h2>UsersListing</h2>@using System.Data;@model IQueryable<COMMON.Models.User> @(Html.Infragistics().Grid<COMMON.Models.User>() .ID("MyGrid") .PrimaryKey("usr_Username") .AutoGenerateColumns(true) .AutoGenerateLayouts(true) .Features(features => { features.Tooltips(); features.Responsive().EnableVerticalRendering(false); features.Resizing(); features.Sorting(); features.Paging().PageSize(10).Type(OpType.Remote).RecordCountKey("ResponseCountKey"); features.Filtering().FilterDialogContainment("window").Mode(FilterMode.Advanced).Type(OpType.Local); }) .ResponseDataKey("Records") .DataSourceUrl(Url.Action("GetUsers","Users")) .Width("1000px") .Height("400px") .DefaultColumnWidth("90px") .DataBind() .AvgRowHeight("200px") .Render() )