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

[Solved] Row color based on model

2 Answers 203 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.
AndrewRick
Top achievements
Rank 1
AndrewRick asked on 09 May 2010, 05:14 PM
Hello,

Is it possible to change row's background depending on a value in the model ? For example, let's say the grid is bound to a Order entity, which has a property 'Status' and now I wish to color every row according to the 'Status' property. Is this possible ?

Many thanks.

Andres R.

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 May 2010, 08:34 AM
Hello Andres Raieste,

Yes it is possible. There are two options depending on your method of databinding:
  1. For server binding use the RowAction method and apply some CSS class with predefined background (or apply the inline style directly) when that condition is met:
    .RowAction(row =>
            {
                if (row.DataItem.OrderID == 10248)
                {
                    row.HtmlAttributes["style"] = "background:red;";
                }
            })
  2. For ajax binding you should use the rowDataBound event:

    .ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
    %>

    <script type="text/javascript">
    function onRowDataBound(e) {
        if (e.dataItem.OrderID == 10248) {
            e.row.style.backgroundColor = "red";
        }
    }
    </script>

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Amey
Top achievements
Rank 1
answered on 10 Apr 2013, 10:27 AM
can you please tell about the same thing via javascript for particular cell?
Tags
Grid
Asked by
AndrewRick
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Amey
Top achievements
Rank 1
Share this question
or