Good day.
I have the following problem, I am using igHierarchicalGrid, only the datasource, I get by json, which food from a store procedure, where I need to send the fields from different tables.
At level 1 there is no problem showing me the data, but the second did not show anything, only the fields to create 2 ViewModels this one with the fields you need at level 1, and other fields with level 2 .
I leave a bit of code, and I hope I can help.
there is my viewmodels:
level 1:
public class RegistroApartadoInicial {
[Key] [ForeignKey("FraccionamientoViewModel")] [Display(Name = "CONTRATO")] public string idContrato { get; set; }
[Display(Name = "CLIENTE")] public string idCliente { get; set; }
[Display(Name = "NOMBRE")] public string Nombre { get; set; }
[Display(Name = "APELLIDO PATERNO")] public string ApellidoPaterno { get; set; }
[Display(Name = "APELLIDO MATERNO")] public string ApellidoMaterno { get; set; }
[Display(Name = "PAQUETE COMERCIAL")] public string idPaqueteComercial { get; set; }
[Display(Name = "ESQUEMA COMERCIAL")] public string EsquemaComercial { get; set; }
[Display(Name = "CARTERA")] public string Cartera { get; set; }
[Display(Name = "ABREVIATURA CARTERA")] public string CarteraAbreviatura { get; set; }
[Display(Name = "MONTO")] public decimal? Monto { get; set; }
[Display(Name = "PAGOS ANTES FINANCIAMIENTO")] public decimal? PagosAntesFinanciamiento { get; set; }
[Display(Name = "MONTO A FINANCIAR")] public decimal? Monto_Financiar { get; set; }
[Display(Name = "INTERES")] public Double? Interes { get; set; }
[Display(Name = "PERIODO PAGOS")] public string Periodo_Pagos { get; set; } public ICollection<FraccionamientoViewModel> ContratoFraccs { get; set; }
}
this is level 2:
public class FraccionamientoViewModel { [Key] [Display(Name = "FRACCIONAMIENTO")] public string idFraccionamiento { get; set; }
[Display(Name = "NOMBRE")] public string FraccionamientoNombre { get; set; }
[Display(Name = "DESCRIPCION")] public string FraccionamientoDescripcion { get; set; }
[ForeignKey("RegistroApartadoInicial")] [Display(Name = "CONTRATO")] public string idContrato { get; set; }
public RegistroApartadoInicial RegistroApartadoInicial { get; set; } }
here my controller:
public ActionResult Apartados(string id) { var cliente = clientes.GetByID(id);
ViewBag.idCliente = cliente.idCliente; ViewBag.Nombre = cliente.Nombre; ViewBag.Ap = cliente.ApellidoPaterno; ViewBag.Am = cliente.ApellidoMaterno; this.ApartadoInicial(id);
return View("ApartadoInicial");
public JsonResult ApartadoInicial(string id) { //aqui utilizo el stored procedure que me trae todos los datos. var dato = da.ContratosPorCliente_Select(id);
return Json(dato, JsonRequestBehavior.AllowGet); }
and my view:
@model IQueryable<CxCModels.ViewModels.RegistroApartadoInicial>@using Infragistics.Web.Mvc;
<script type="text/javascript"> $(document).ready(function () { var idcliente = document.getElementById("inputCliente").value; $.getJSON( "/BusquedaCliente/ApartadoInicial", { id: idcliente },
function (json) {
$("#grid2").igGrid("dataSourceObject", json); $("#grid2").igGrid("dataBind"); }); }); </script>
<div style=" vertical-align: 200px;">
@(Html.Infragistics().Grid(Model).ID("grid2").Width("800px").AutoGenerateColumns(false).LoadOnDemand(true) .PrimaryKey("idContrato").AutoCommit(true).DefaultColumnWidth("150px") .Columns(column => { column.For(x => x.idContrato); column.For(x => x.EsquemaComercial); column.For(x => x.CarteraAbreviatura).Width("200px"); column.For(x => x.Monto); column.For(x => x.PagosAntesFinanciamiento).Width("200px"); column.For(x => x.Monto_Financiar); column.For(x => x.Interes); column.For(x => x.Periodo_Pagos);
}) .AutoGenerateLayouts(false) .ColumnLayouts(layouts => { layouts.For(x => x.ContratoFraccs).PrimaryKey("idFraccionamiento").ForeignKey("idContrato").DefaultColumnWidth("150px").LoadOnDemand(true).AutoGenerateColumns(false).Columns(childcols1 => { childcols1.For(x => x.idContrato); childcols1.For(x => x.idFraccionamiento); childcols1.For(x => x.FraccionamientoNombre); childcols1.For(x => x.FraccionamientoDescripcion);
}); }) .Features(features => { features.Paging().Type(OpType.Local).PagerRecordsLabelTemplate("${startRecord} - ${endRecord} DE ${recordCount} REGISTROS").PageSize(10).FirstPageLabelText("").FirstPageTooltip("Ir a primera pagina").PrevPageLabelText("").PrevPageTooltip("Ir a pagina Anterior").ShowPagerRecordsLabel(true) .LastPageLabelText("").LastPageTooltip("Ir a Ultima pagina").NextPageLabelText("").NextPageTooltip("Ir a Siguiente pagina").PageSizeDropDownLabel("MOSTRAR").PageSizeDropDownTrailingLabel("REGISTROS"); }) .Height("400px") .DataBind() .Render())
</div>
I hope anybody helpme. thanks in advance.
this an image of my grid:
Regards
Hi Tsvetelina.
I was able to solve the problem, it's Works!!, now I have a doubt as to the multi grid layouts direct in my controller, like this:
http://samples.infragistics.com/jquery/hierarchical-grid/multiple-levels-multiple-layouts
again thanks in advance for your help.
Christhian
Hello Tsvetelina.
thanks for your response.
the grid is working almost, just wanting to get childgrid data, I have the following problem, I took them out data from a stored procedure, I have a table in the database, then I have the following questions:
1. I do not know who put in "layout.Key =" put any data or ignore it and telling me "undefined is not found". I do this in igGrid but changing datasource when i put a data and search in database, but igHierarchicalGrid work diferent.
2. there is any problem handling the data stored procedure, I do it because they are data from several tables I need to display in the grid.
I hope you can helpme.
NOTE: I'm mapping stored procedures in the Entity Model (edmx).
this is the code of my method for the child:
public JsonResult Grid2(string path, string layout){ idContratotemp = path.Substring(path.IndexOf(":") + 1); idContratotemp = this.getIdContrato(idContratotemp);
var dato = da.ContratoFraccionamientoDetalle_Select(idContratotemp).ToList(); grid.DataSource = dato.AsQueryable();
return grid.GetData(path, layout);}
Hello Christhian,
Thank you for using our igHierarchicalGrid.
Please refer to the documentation regarding loading data on demand in MVC:
http://help.infragistics.com/NetAdvantage/jquery/2012.1?page=igHierarchicalGrid_Load_on_Demand.html
There is clearly stated that when configuring Load On Demand in MVC, the igHierarchicalGrid cannot be initialized in the View.
Instead, you need to set all igHierarchicalGrid properties in either the Controller or in the Model.
For the purpose I recommend you reading the article
http://community.infragistics.com/blogs/damyan_petev/archive/2012/02/15/jquery-hierarchical-grid-load-on-demand.aspx
and also taking look at the sample attached there :
http://media.infragistics.com/community/Release/11.2/JQUERY/Hierarchical_Grid-Load_On_Demand/load-on-demand_Demo.zip
Please notice that you can use GetData() method (without parameters for the parent and with 2 parameters for the child level) to return the data in JSONResult format because the igHierarchicalGrid requires that from the DataSourceUrl methods.
Let us know if you have further questions.