I'm doing a table using HTML in ASP.NET MVC. I am uploading the information on the company's income statement, and there are quite a few records, and when loading the table it takes a long time, as well as wanting to filter information, as it reloads the data (the filters are by dates).
As you can see the table is tree type, since the accounts are related to each other, an account can have many daughter accounts and daughters can have daughters, and so up to N
times.
The father account carries the sum of his daughters and so on until the last father is reached.
To fill the table I use a recursive view, then I show the code to fill and create that table.
@helper GetHtml (List<SUI.Web.Common.Entidades.Dashboard.BG> Modelo, String Padre_ID, int con)
{
<table align="center" border="1"class="table table-condensed table-bordered table-hover" id="tab1">
@{
string currentID = "";
int rowIndex = 0;
var lis = (Modelo.Where(a => a.CuentaPTPadre == Padre_ID)).ToList();
foreach (var i in Modelo.Where(a => a.CuentaPTPadre == Padre_ID))
{
if (i.CuentaPT == currentID)
{
continue;
}
else
{
if (con == 0) {
con = 1;
<thead>
<tr>
<th>Nombre</th>
<th>Cuenta</th>
<th>Importe</th>
<th>Importe 2</th>
</tr>
</thead>
}
rowIndex++;
currentID = i.CuentaPT;
var Sub = Modelo.Where(a => a.CuentaPTPadre.Equals(i.CuentaPT)).ToList();
var NuevoModelo = Modelo.Where(a => !a.CuentaPT.Equals(i.CuentaPT)).ToList();
<tbody>
<tr>
<td>
@if (Sub.Count > 0)
{
<span class="icon icon-e" style="float:left; cursor:pointer;" id="iconv" onclick="b()"></span>
}
else
{
<span style="display:inline-block;width:14px"> </span>
}
@i.Nombre
</td>
<td>@i.CuentaPT</td>
<td>@i.Importe </td>
<td>@i.importe2</td>
</tr>
<tr style="display:none;">
@if (Sub.Count > 0)
{
<td colspan="4" class="innerTable">
@NestedData.GetHtml(NuevoModelo, i.CuentaPT,1)
</td>
}
else
{
<td colspan="4" ></td>
}
</tr>
</tbody>
}
}
}
</table>
}
The model is filled from the controller, to fill the model I make a foreach
that separates the accounts and then relate these accounts (parents and daughters) but this is somewhat slow, try using linq, but only achieve it until 2 levels, would there be a way to do it using only linq recursively until N
levels?
In summary, my question is, is there an easier way to relate the daughter accounts with their parents?
Is it better to get the sum of the daughters accounts from the query or add directly in the filling of the table?
Could you help me make a table that I loaded faster, and that when filtering does not have to reload the model and fill the table ?, or if someone has another solution would appreciate it enough.