Sunday, February 24, 2013

Workaround for p:column colspan

Recently, I was facing a problem with the p:datatable colspan attribute.
I wanted to conditionally colspan the table cell, but I failed to do that. And I found its impossible to do it now from the Primefaces forum.

conditional colspan in p:column

Finally, I came out with a workaround with jQuery.
Instead of the colspan attribute, I used the styleClass attribute to dynamically adjust the table's colspan.

Platform: Primefaces 3.4
Server: Tomcat 7

Steps:
1. Declare the styleClass attribute with dynamic conditions.
conditional colspan in p:column
2. Declare the jQuery script to adjust the table colspan on page loading.
conditional colspan in p:column
  • above script showed the jQuery lookup any element where className = 'myStyleClass', then adjust the colspan attribute with my desired value. 
  • myStyleClass is just a unique name for jQuery to lookup the element, it could be any name. 
  • 4 is just an example, it could be any desired colspan value. 


Done!!

With the above steps, jQuery will dynamically adjust the table colspan based on the passed in conditions. 

LinkWithin

Related Posts Plugin for WordPress, Blogger...