Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
530
Hierarchicalgrid with mvc and entity framework 4.0
posted

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.Processos
join c in db.Clientes on p.IDCliente equals c.IDCliente
orderby p.IDProcesso descending
where p.Rem == 0
select 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";
else
return "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..

Parents
No Data
Reply
  • 5513
    Offline posted

    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

Children