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

Add Column with sum result of other 2 columns

4 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eloy
Top achievements
Rank 1
Eloy asked on 29 Mar 2012, 10:35 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());
}


4 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 04 Apr 2012, 06:27 AM
Hello Eloy,

You could consider using the GridCalculatedColumn in order to achieve your goal. It allows making some operations with a list of fields from the grid datasource and display the result. See a demo here:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/calculatedcolumns/defaultcs.aspx

All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Eloy
Top achievements
Rank 1
answered on 04 Apr 2012, 08:14 AM
Thx for reply, but i want to make it in razor view, and i can't put a GridCalculatedColumn.
i see the agreggate, but i only make it for the footer section of the column.
0
Accepted
Tsvetina
Telerik team
answered on 04 Apr 2012, 09:20 AM
Hello Eloy,

It seems I missed this out - do you use an ASP.NET AJAX RadGrid or an MVC Grid? If it is the second, post your question in the MVC forums:
http://www.telerik.com/community/forums/aspnet-mvc/grid.aspx

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Eloy
Top achievements
Rank 1
answered on 04 Apr 2012, 10:00 AM
Thx for reply, yes i don't see i'm in the ajax forum :S:S .

Sorry for the inconvenience. Thank you so much.
Tags
Grid
Asked by
Eloy
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Eloy
Top achievements
Rank 1
Share this question
or