Conditional Rows and Columns
By Tim Dexter on Nov 19, 2007
Back from OOW and fighting a cold from all that 'sea level' air - give me the moutains any day. I dont really mean that - I lived by the ocean until we left the UK in '99 - I miss it, but standing atop Pikes Peak is a sight to behold. I promised normal service when I got back from crazy town, this morning there was a question on the forum asking how to achieve conditional rows and columns. I have admit I thought I had covered that here or in the documentation ... I can not find it so here goes.
This is pretty straightforward and later releases of the template builder will help you achieve even more easily. Basically you need an 'if' statement that will cover the complete row.
Notice the 'C' field, this contains the conditional code:
see the '@row' thats going to apply the condition to the whole row for us. You can either hand code it or as I mentioned the template builder will do it for you. It provides a friendly dialog for simple conditions - if you have more complex requirements then you are going to have to get your feet wet or hands dirty in the code.
The '@incontext' is a useful addition to the 5.6.3 release shortening code requirements further to update attributes, in this case the color.
The above condition will highlight the text red for the whole row where an employee has a salary greater than 2000.
This runs along similar lines to rows ie we have an '@column' command. Sadly the template builder cannot help you here ... yet. But the code is not tough to write. I have written something a little more interesting for the conditional column formatting. I have grouped the employees by department and then added some conditional logic to hide the Job column if the department name is 'Accounting'
Notice the 'CC' fields, I need one for the column header and the data cell, the contents are simple:
<?if@column:DNAME !='ACCOUNTING'?><?end if?>
The @column defines the extent of the conditional statement ie just to the column, when executed we get the following:
notice the missing Job column.
Now I have used some simple conditions you can of course get pretty complex in the logic, you're limited only by your imagination and your XSL knowledge, there by hangs a tale - you got questions get to the forum, Im there in Colorado mornings and late evenings. Get the template and data here.