JqGridHelper without generics

Mar 2, 2012 at 10:54 AM

thanks for this great library that helps me to save a lot of time.

In my project, in one grid, I haven't a static model but I need to create the columns at runtime basing on some data elaborations that are parametrics.

So I couldn't use the JqGridHelper because it has a generic type and I haven't seen any possibility to build the columns manually without using a "TModel".

So i simply make a copy of the class JqGridHelper<TModel> (i called it JqGridHelper), I remove all "<TModel>" string from the file and I add the get property access to the Option property (of type JqGridOptions, no more generic).
And with this easy step, I can create a grid at runtime specifing the columns to add.

For example here is the basics grid with the column added manually:

var opt = new Lib.Web.Mvc.JQuery.JqGrid.JqGridOptions("grid");
            opt.ColumnsModels.Add(new JqGridColumnModel("ProductID") { Index = "ProductID", Alignment = JqGridAlignments.Left, SortingType=JqGridSortingTypes.Int });
            opt.ColumnsModels.Add(new JqGridColumnModel("ProductName") { Index = "ProductName", Alignment = JqGridAlignments.Left });
            opt.ColumnsModels.Add(new JqGridColumnModel("SupplierID") { Index = "SupplierID", Alignment = JqGridAlignments.Left });
            opt.ColumnsModels.Add(new JqGridColumnModel("CategoryID") { Index = "CategoryID", Alignment = JqGridAlignments.Left });
            opt.ColumnsModels.Add(new JqGridColumnModel("QuantityPerUnit") { Index = "QuantityPerUnit", Alignment = JqGridAlignments.Left, SortingType = JqGridSortingTypes.Float });
            opt.ColumnsModels.Add(new JqGridColumnModel("UnitPrice") { Index = "UnitPrice", Alignment = JqGridAlignments.Left, SortingType = JqGridSortingTypes.Float });
            opt.ColumnsModels.Add(new JqGridColumnModel("UnitsInStock") { Index = "UnitsInStock", Alignment = JqGridAlignments.Left , SortingType=JqGridSortingTypes.Int});

            opt.Url = Url.Action("Products");
            opt.DataType = JqGridDataTypes.Json;
            opt.MethodType = JqGridMethodTypes.Post;

            opt.LoadOnce = true;
            opt.SortingName = "ProductID";
            opt.SortingOrder = JqGridSortingOrders.Asc;
            opt.ViewRecords = true;


I think that you shoud add the possibility to build the column grid manually as I done it (maybe not simply making a copy&paste of the class) but I hope to have given you a good idea


thank you