Hello -
I need to have multiple grids to a single asp.net MVC page? To add even more complexity the number of grids is variable also. I might be able to accomplish it with a hierarchical grid but thought I would explore this first. Thanks much
Hello Andrew,
After investigating this further, I determined that multiple grids could be defined in one page. Number of grids based on a variable could be rendered by defining the grids in a loop. I have prepared a sample, demonstrating the described behavior. The defined grids contain only basic options, however there is no problem in defining other options as well:
$(function () {
for (var i = 1; i < numberGrids + 1; i++) {
var grid = "grid" + i;
$("#" + grid).igGrid({
autoGenerateColumns: true,
width: "500px",
dataSource: products[i - 1]
});
}
Below I am attaching the sample. Please test it on your side and let me know if you need any further information regarding this matter.
Regards,
Monika Kirkova,
Infragistics
MultipleIgGrids.zip
Thanks very much. I will try this out. I have mostly been using MVC and writing the code in the controller. Is that possible also? thanks very much
The data for the models could be defined in the controller and passed to the view. Furthermore the grids could be defined in a @for loop in the view and bound to the model as follows:
@for(int i = 0; i < 2; i++)
{
@(Html.Infragistics().Grid(Model.Customers.AsQueryable())
.ID("grid" + i)
.AutoGenerateColumns(true)
.DataBind().Render())
Below I am attaching the modified sample. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce.
Looking forward to hearing from you.
Regards, Monika Kirkova, Infragistics
MultipleGrids.zip
Thanks much for this. This really helped. Here is the solution I ended up coming up with. The model was an array of gridModels.
View:
@foreach (var m in Model)
@(Html.Infragistics().Grid(m)) <br />}
Controller:
[ActionName("editing")] public ActionResult GridUpdating(int QuotaID, string IONumber) { var modelList = new List <GridModel>();
//Infragistics Grid
var quotaDetailList = projectPricingBAL.getCostGridForQuotaFlatDemo(QuotaID); GridModel gridModel = new GridModel(); gridModel.AutoGenerateColumns = false; gridModel.ID = "Grid_QuotaEdit"; gridModel.PrimaryKey = "ID"; gridModel.DataSource = quotaDetailList.AsQueryable(); InitializeGridOptions(gridModel);
modelList.Add(gridModel); //add to an array
var quotaDetailList2 = projectPricingBAL.getCostGridForQuotaFlatDemo(25869); //hardcoded for testing
GridModel gridModel2 = new GridModel(); gridModel2.AutoGenerateColumns = false; gridModel2.ID = "Grid_QuotaEdit2"; gridModel2.PrimaryKey = "ID"; gridModel2.DataSource = quotaDetailList2.AsQueryable(); InitializeGridOptions(gridModel2);
modelList.Add(gridModel2); //trying to add to an array
return View(modelList); }
I am glad that you find my suggestion helpful and were able to solve your issue.
Thank you for using Infragistics components.