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

[Solved] ClientRowTemplate row formatting

1 Answer 195 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.
Paul
Top achievements
Rank 1
Paul asked on 31 Oct 2011, 05:55 PM
In my grid, I am updating the text color of a row based on a value.  The grid uses ajax(Select) binding and looses the background style when an ajax call is made. 

How do I maintain the style of the row when ajax binding occurs? 

Html.Telerik().Grid(Model.MessageGridViewModelCollection)
    .Name("Messages")
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax().Select(Model.AjaxAction, Model.AjaxController, Model.AjaxParameters).Enabled(true);
 
    })
    .Columns(c =>
    {
        c.Bound(o => o.LevelName);
        c.Bound(o => o.Message);
        c.Bound(o => o.EntityName);
    })
    .RowAction(row =>
    {
        string backgroundcolor = "black";
        if (row.DataItem.LevelName == Level.Required)
        {
            backgroundcolor = "#CC0033";
        }
        else if (row.DataItem.LevelName == Level.Warning)
        {
            backgroundcolor = "#D75D00";
        }
        row.HtmlAttributes["style"] = "color: " + backgroundcolor;
    })
    .Sortable()
    .Resizable(p => p.Columns(true))
    .Filterable(f => f.Enabled(true))
    .Pageable( f => f.PageSize(15))
    .Render(); 



1 Answer, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 03 Nov 2011, 06:45 PM
Resolved.  I needed to add ClientEvents to my grid with a javascript event.


Html.Telerik().Grid(Model.MessageGridViewModelCollection)
    .Name("Messages")
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax().Select(Model.AjaxAction, Model.AjaxController, Model.AjaxParameters).Enabled(true);
  
    })
    .Columns(c =>
    {
        c.Bound(o => o.LevelName);
        c.Bound(o => o.Message);
        c.Bound(o => o.EntityName);
    })
    .RowAction(row =>
    {
        string backgroundcolor = "black";
        if (row.DataItem.LevelName == Level.Required)
        {
            backgroundcolor = "#CC0033";
        }
        else if (row.DataItem.LevelName == Level.Warning)
        {
            backgroundcolor = "#D75D00";
        }
        row.HtmlAttributes["style"] = "color: " + backgroundcolor;
    })
    .ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
    .Sortable()
    .Resizable(p => p.Columns(true))
    .Filterable(f => f.Enabled(true))
    .Pageable( f => f.PageSize(15))
    .Render();
 
<script type="text/javascript">
    function onRowDataBound(e) {
        if (e.dataItem.Level == 1) {
            e.row.style.color = "#CC0033";
        }
        if (e.dataItem.Level == 2) {
            e.row.style.color = "#D75D00";
        }
    }
</script>
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Share this question
or