Skip to main content
February 1, 2012
Question

How to set width of cfgid in percentage?

  • February 1, 2012
  • 1 reply
  • 899 views

I have to make the cfgrid compatible irrespective of screen size. But it is not taking width in perecntage(giving error : Attribute vallidation error, height/width can not be given in percentage.)

I put the cfgrid inside a div and set width of the div as 100%, but it has no effect on the cfgrid.

Can anyone please give me a solution??

I will be thankfull towards any helpfull suggestion.

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
February 1, 2012

width="number_of_pixels", for example, width="600"

February 2, 2012

@BKBK : ya, that is possible; but it will make it's width a fixed sized. It will have look and feel issue when we switch between different size of screens.

That's why i was asking how to do it in % ?   or is there any other way to make it compatible irrespective of screen size??

BKBK
Community Expert
Community Expert
February 3, 2012

Then you have to find a way to get the browser to send information about screen size to ColdFusion. One way to do it is by means of AJAX. Another, in my opinion much simpler way, is to get Javascript to store the screen size as a cookie, and then to get ColdFusion to read the cookie. I was thinking of something like this

<script type="text/javascript">

var browserWidth = screen.width;

var browserHeight = screen.height;

var expiryDate=new Date();

/*set expiry date tomorrow*/

expiryDate.setDate(expiryDate.getDate()+1);

document.cookie= 'browserWidth='+browserWidth+',browserHeight='+

                            browserHeight+',expires='+expiryDate;

</script>

<cfset percentWidth = 90>

<cfif isDefined("cookie.browserWidth")>

    <cfset browserWidth = cookie.browserWidth>

<cfelse>

    <cfset browserWidth = 800>

</cfif>

<cfset gridWidth = int(percentWidth*browserWidth/100)>

<cfform>

<cfgrid format="html" name = "myGrid" width="#gridWidth#">

</cfgrid> 

</cfform>