This is a migrated thread and some comments may be shown as answers.

[Solved] column with the result of sum other 2 columns

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eloy
Top achievements
Rank 1
Eloy asked on 04 Apr 2012, 10:01 AM
I have this code, I get data from DB, and i need to create another column in grid with de sum of column1 and 2.

view Razor:

@model List<Project.Models.VW_VisitasPorNumeroVisitas>
 
@{
    ViewBag.Title = "Index";
}
 
 
 
<h2>Visitas por Numero de Visitas</h2>
 
@(Html.Telerik().Grid(Model)
        .Name("RadGrid1")
        .Sortable()
        .Filterable()
        .Pageable()
        .Footer(true)
        .NoRecordsTemplate("No hay registros")
        .Columns(columns =>
        {
            columns.Bound(o => o.NumVisitas)
                .Title("Numero de Visitas")
                .Aggregate(agg => agg.Sum())
                .FooterTemplate(@<text> Visitas Totales: <span >@item.Sum</span> </text>);
            columns.Bound(o => o.TotalVisitas)
                .Title("Cantidad de Visitas");
                 
            columns.Bound(o => o.NumVisitas)
                .Title("% Visitas");
        })     
)

CS:

public ActionResult Index()
{
    var visitasPorNum = from a in db.VW_VisitasPorNumeroVisitas
                        select a;
 
    return View(visitasPorNum.ToList());
}

1 Answer, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 04 Apr 2012, 01:28 PM
Do you try to change your model?

public class VW_VisitasPorNumeroVisitas
{
public int NumVisitas {get; set;}
public int TotalVisitas{get; set;}

public int Sum {get{return NumVisitas + TotalVisitas; }}
}


columns.Bound(o => o.Sum )
Tags
Grid
Asked by
Eloy
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Share this question
or