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

Conditional formatting of the row.

4 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dasha
Top achievements
Rank 1
Dasha asked on 14 Jul 2011, 05:52 PM
Hello,

I'm trying to implement dynamic conditional formatting in the RadGrid.  The conditional formatting settings are supplied dynamically as a collection of filters that I need to apply on the server and have the grid display the corresponding styling.  I can't find any relevant documentation that could enable me to do so.  There's this example:
protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
{
     //Is it a GridDataItem
     if (e.Item is GridDataItem)
     {
           //Get the instance of the right type
           GridDataItem dataBoundItem = e.Item as GridDataItem;
 
           //Check the formatting condition
             if (int.Parse(dataBoundItem["Size"].Text) > 100 )
           {
                 dataBoundItem[ "Received"].ForeColor = Color.Red;
                 dataBoundItem[ "Received"].Font.Bold = true;
                 //Customize more...
           }
     }
}

But the problem is that I don't know if it will be one boolean clause or three.  So the condition may be "Title == "Home"" or it could be "Title == Home AND Amount <= 10"  So I need to be able to dynamically build out the filter conditions.

I tried using the OnRowDataBound client side event and construct the javascript dynamically in C#, but the event is not firing because I'm not binding on the client side, but in the OnNeedDataSource event.

Any ideas?

4 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 20 Jul 2011, 09:06 AM
Hello Dasha,

Not sure I do understand what you are trying to achieve.

'But the problem is that I don't know if it will be one boolean clause or three.'
-You can check whether the specified arguments are provided in the ItemDataBound and build the condition accordingly. This way you just have to write more conditional statements in the ItemDataBound.

What do you mean by dynamically building filter expressions? Do you mean grid filter expressions or just some data that you need for styling?

Can elaborate a little bit more on what your scenario is?

Best wishes,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Dasha
Top achievements
Rank 1
answered on 20 Jul 2011, 12:46 PM
Genti,

Thank you for your help on this topic.  What I mean is that I don't know ahead of time what the conditions are.  Your example shows how to check for if (int.Parse(dataBoundItem["Size"].Text) > 100), this assumes that I know all three factors ahead of time: that I'll be checking the size(column) to be over(logical operator) 100(value).  But we would like to provide our users the flexibility to define several conditions if they wish and then dynamically interpret the conditions in code.  So we may end up without any conditions at all, or we may end up with something like "Size > 100 AND Title.Contains("Task")".  I hope this explanation is a little more clear.

Please visit this link to see a example of what I mean:
http://www.intersoftpt.com/Community/WebGrid/FormatCondtions/
the CustomConditionText allows the developer to enter several conditions, and because it is a string I can build it dynamically base on the user input.
0
Genti
Telerik team
answered on 22 Jul 2011, 11:41 AM
Hi Dasha,

I am attaching a sample solution that illustrates how you can achieve this kind of dynamical formatting with RadGrid.

In order to have a dynamic system of filtering the row you can combine the usage of RadFilter and RadGrid.
The RadFilter is going to generate the dynamic query that is required for filtering.
Then the trick is to get the query from the RadFilter and apply it to the datasource of the grid.
This way you get the IDs of the items that require formatting.
In the end what is left is to style them in the ItemDataBound event of the grid.



Regards,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Dasha
Top achievements
Rank 1
answered on 22 Jul 2011, 12:56 PM
Genti,

This sounds like exactly what I need! I'm eager to try it out.  I'll let you know how it works.
Tags
Grid
Asked by
Dasha
Top achievements
Rank 1
Answers by
Genti
Telerik team
Dasha
Top achievements
Rank 1
Share this question
or