Hi,
is it possible to tell me how can to use hierarchicalgrid using entities.
in my project i am using the simple grid..
but in those grids i have got duplicate information..
I was trying to change the grid to hierarchicalgrid...
lets say that i have a table Clients, and a table Process.
A client can have multiple process..
The client is discribed by a name, and the process is discribed by the hour of creation...
how can i create a hierarchicalgrid? in order that the main grid got the client name, and the subgrid got the process?
in the current project i have created a viewmodel containing the information that i need.
here is the code..
viewmodel class
public class VMProcessoCliente{[Key]public int IDProcesso { get; set; }public string NomeCliente { get; set; }public string DataInserido { get; set; }public string Estado { get; set; }
public static IQueryable<VMProcessoCliente> GetListaProcessosClientes(){MvcIdonic db = new MvcIdonic();
var processos = (from p in db.Processosjoin c in db.Clientes on p.IDCliente equals c.IDClienteorderby p.IDProcesso descendingwhere p.Rem == 0select new { IDProcesso = p.IDProcesso, NomeCliente = c.Nome, DataInserido = p.DataInserido, Estado = p.Estado }).ToList().Select(c => new VMProcessoCliente{IDProcesso = c.IDProcesso,NomeCliente = c.NomeCliente,DataInserido = c.DataInserido.ToString(),Estado = GetValEstado(c.Estado)});
return processos.AsQueryable<VMProcessoCliente>();
}
private static string GetValEstado(int p){if (p == 1)return "Start";elsereturn "close";}
my index.cshtm containig the grid
@( Html.Infragistics().Grid<Licenciamento_v2.Areas.Idonic.ViewModel.VMProcessoCliente>().Caption("Processo").ID("grid_Processo").DefaultColumnWidth("200px").PrimaryKey("IDProcesso").Columns(column =>{
column.For(x => x.NomeCliente).DataType("string").HeaderText("Nome do Cliente");column.For(x => x.DataInserido).DataType("DateTime").HeaderText("Data de Criação do Processo");column.For(x => x.Estado).HeaderText("Estado");column.For(x => x.IDProcesso).Width("0px");
}).Features(features =>{features.Paging().PageSize(20).PrevPageLabelText("Previous").NextPageLabelText("NEXT");features.Sorting().Mode(SortingMode.Single);features.Selection().MultipleSelection(false);features.Filtering().Mode(FilterMode.Simple);features.Updating().EnableAddRow(false).EnableDeleteRow(true).EditMode(GridEditMode.None);
}).DataSourceUrl(Url.Action("ListarProcessos")).UpdateUrl(Url.Action("DeleteProcessos")).Render())
and here is the controller code to list all the information
[GridDataSourceAction]public ActionResult ListarProcessos(){return View(Licenciamento_v2.Areas.Idonic.ViewModel.VMProcessoCliente.GetListaProcessosClientes());}
this gives me a grid with information about the process date of creation, the client of the process..
the problem is that the client can contain multiple process..
so i can ihave multiple rows with the same client name..
what i want is to have a single row per client, and in the subgrid have the info about the process...
how can i do this?
thanks in advance..
Hello Hugo,
To create a hierarchical grid you should specify the child layout(s) as the hierarchy is not inferred from the model. A sample of a hierarchical grid created in the view with chaining, similar to your case, can be found here: http://igniteui.com/hierarchical-grid/editing-dataset.
Please, let me know if you have any other questions or need additional help!
Best regards,
Stamen Stoychev
i manage to get it working last night...~
the processo class
public class Processo { [Key] public int IDProcesso { get; set; } public int IDCliente { get; set; } public DateTime DataInserido { get; set; } public int Estado { get; set; } public int IDU { get; set; } public int Rem { get; set; } public DateTime TStamp { get; set; }
the view model Client
public class Hierarchicalgrid {
public int IDCliente { get; set; } public string NomeCliente { get; set; }
public List<Processo> Processos { get; set; }
public static IQueryable<Hierarchicalgrid> GetListProcessos() { MvcIdonic db = new MvcIdonic();
var processos = (from c in db.Clientes //join p in db.Processos on c.IDCliente equals p.IDCliente orderby c.Nome descending where c.Rem == 0 select new { IDCliente = c.IDCliente, NomeCliente = c.Nome }).ToList().Select(c => new Hierarchicalgrid { IDCliente = c.IDCliente, NomeCliente = c.NomeCliente, Processos=GetListProcessosByIDCliente(c.IDCliente) });
return processos.AsQueryable<Hierarchicalgrid>();
private static List<Processo> GetListProcessosByIDCliente(int p) { MvcIdonic db = new MvcIdonic(); List<Processo> ListP = new List<Processo>(); ListP = db.Processos.Where(x => x.IDCliente == p).ToList(); return ListP; } }
the view.cshtml
@(Html.Infragistics().Grid <Licenciamento_v2.Areas.Idonic.ViewModels.Hierarchicalgrid>()
.AutoGenerateColumns(false) .AutoGenerateLayouts(false) .Caption("Processo") .ID("grid_Processo") .Columns( cols=>{ cols.For(x => x.IDCliente).HeaderText("ID"); cols.For(x => x.NomeCliente).HeaderText("Name"); }) .ColumnLayouts( layout=>{ layout.For(x => x.Processos).Columns(cols=>{ cols.For(x => x.IDProcesso).HeaderText("ID"); cols.For(x => x.DataInserido).HeaderText("Name"); cols.For(x => x.IDCliente).HeaderText("CustomerID"); }); }) .DataSourceUrl(Url.Action("ListarProcessos2")) .Width("400px") .DataBind() .Render() )
the controller
[GridDataSourceAction] public ActionResult ListarProcessos2() { return View(Licenciamento_v2.Areas.Idonic.ViewModels.Hierarchicalgrid.GetListProcessos()); }
Now how can i transform this code to load on demand...
i am currently creating a similar sample project wit companys and user...
but i want to add the load on demand part..
How can i do that...
thanks