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

Alternate Table Background Color When the Value of a Single Column Changes

6 Answers 390 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Sadie
Top achievements
Rank 2
Sadie asked on 28 Apr 2015, 10:54 PM

Hello Telerik Team!

 I have a report in which I would like to use conditional formatting to change the background color of rows in a table based on a change in the value of one of the columns. Something similar to this example in Excel: http://superuser.com/questions/553899/alternate-grid-background-color-in-excel-when-a-value-of-a-single-column-changes

Is there a way to do this in the Edit Expression Dialog in Telerik Reporting Q3 2014?

Thanks so much!

6 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 29 Apr 2015, 12:47 PM
Hello Sadie,

You can achieve the described scenario using conditional formatting. Inside the conditional formatting rule expression you can reference a data field from your data source (value of one of the columns).
For more information, please refer to the Conditional Formatting help article.

A similar scenario is described in the Display Reports with alternating style rows help article.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Sadie
Top achievements
Rank 2
answered on 29 Apr 2015, 07:56 PM

Hello Nasko!

 Thank you for your reply. Apologies for not being more specific in my question. What I am looking for is a way to compare rows like in Excel (e.g. http://superuser.com/a/554989 - B2 is compared to B1 to tell whether the value in column B has changed). In the Report Designer, it seems that only columns can be compared to each other and not rows. Is there a way of comparing rows to detect whether a value has changed?

Thanks so much!

0
Nasko
Telerik team
answered on 30 Apr 2015, 08:53 AM
Hello Sadie,

The approach to get the previous record's value in Telerik Reporting is via SQL code in the query to the database (or programmatically inside your business object if ObjectDataSource is used).

For example, you can calculate the difference between the current row value and the previous row value and this is how such SQL query will look when using the AdventureWorks sample database:
USE AdventureWorks
GO
    
SELECT COALESCE(t1.SickLeaveHours - t2.SickLeaveHours, 0) AS [Difference], t1.EmployeeID, t1.Title, t1.SickLeaveHours FROM HumanResources.Employee t1
LEFT JOIN HumanResources.Employee t2 ON
t1.EmployeeID = t2.EmployeeID + 1

Then use the Difference data field in conditional formatting rules to change the style of the row.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Sadie
Top achievements
Rank 2
answered on 30 Apr 2015, 10:52 PM

Hello Nasko!

Thank you so much for your reply! I noticed that in your query you are calculating a difference. I assume that the row values are therefore numerical. In my dataset I want to determine when a string has changed. Can I do that using a SQL query too?

 Thanks so much!

0
Nasko
Telerik team
answered on 05 May 2015, 09:31 AM
Hello Sadie,

Yes, you can do that in the SQL query for any data type, as long as you select the required field from the second table (t2). For more information on comparing strings in T-SQL, please refer to the String Functions (Transact-SQL) MSDN article.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
em
Top achievements
Rank 1
answered on 04 May 2016, 01:06 PM

Hello Telerik Team,
I set Conditional formatting and it worked great, but after a while I notice that condition was delete in some field in row. I can not define why and when it happenŠµd. Report was made and tested and the project is not open again.  I work in other projects in the solution and build a solution in Visual studio 2010 and C#.

For ex. this.textBox27.ConditionalFormatting.AddRange(new Telerik.Reporting.Drawing.FormattingRule[] {
            formattingRule1});

after a while will be

this.textBox27.ConditionalFormatting.AddRange(new Telerik.Reporting.Drawing.FormattingRule[] {
            });

Tags
Report Designer (standalone)
Asked by
Sadie
Top achievements
Rank 2
Answers by
Nasko
Telerik team
Sadie
Top achievements
Rank 2
em
Top achievements
Rank 1
Share this question
or