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
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.
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!
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.
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!
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.
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[] {
});