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

[Solved] JS Formatting Telerik Aggregates summation row

1 Answer 24 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.
Erwin
Top achievements
Rank 1
Erwin asked on 05 Jun 2012, 09:38 AM
Hi all,

I have a Telerik grid in ASP.NET MVC 3 with a money column. I've formatted the color of the cell to green using this javascript:

<script type="text/javascript">
    function onRowDataBound(e) {
        if (e.dataItem.Amount < 0) {
            e.row.cells[2].innerHTML = e.row.cells[2].innerHTML.replace("-", "");
            e.row.cells[2].style["color"] = "red";
        }
        else {
            e.row.cells[2].style["color"] = "green";
        }
}
</script>

How can I do the same for the Aggregates row, and make the negative values appear in red and the positive values in green?
How do I replace the $ sign with a € sign?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Jun 2012, 07:29 AM
Hello Erwin,

In order to customize the aggregates row, you could call a JavaScript function from the client group or footer templates which to determine the color of the element e.g.
.ClientGroupHeaderTemplate("<div style='background-color:<#= getColor(data)#>;'> <#= Key #></div>");
function getColor(data) {
    //remove the currency sign and check which color should be returned
    var Key = data.Key.replace(/\$/, "");
    if (Key > 0) {
        return "red";
    }
    else {
        return "green";
    }
}
Changing the currency symbol should be done automatically, if globalization is enabled from the ScriptRegistrar and the current culture CurrencySymbol is "€". The alternative is to use a template and custom code to replace the character.

Kind regards,
Daniel
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Erwin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or