Quick and easy column alignment for CFGRID

Aug 23, 2007

When using the CFGRID tag (type="html"), there is no built-in way to align the data in the columns.  The dataalign attribute of the CFGRIDCOLUMN tag is not available for the HTML grid type.  There is a simple CSS trick to align the columns.

Each column in the grid has its own css class, and there is also a class that applies to all columns.  The x-grid-col class allows you to apply formatting to all of the columns at once, for example: .x-grid-column {text-align:right;}.  The rest of the columns have numbers associated with them, starting with 0 as the first column.  So, the code below aligns all of the grid columns to the right, then sets only the first and second columns to align left.

 <style type="text/css">
    .x-grid-col {text-align:right;}
    .x-grid-col-0 {text-align:left;}
    .x-grid-col-1 {text-align:left;}
</style>

 You can also update just the column headers using a similar method.  The  headeralign attribute of cfgridcolumn also doesn't work for HTML grids.

 <style type="text/css">
    .x-grid-hd {text-align:center;}      
    .x-grid-hd-0-0 {text-align:left;}     
    .x-grid-hd-0-1 {text-align:left;}
</style>

Comments

Kate Juliff

Kate Juliff wrote on 02/14/08 9:46 AM

Great tip! Very helpful.
andrew lorien

andrew lorien wrote on 03/24/08 9:41 PM

and to re-enable text wrapping for the table,

.x-grid-row td {white-space:normal;}

it didn't work straight off for me, but you should be able to do it per column with
.x-grid-td-1 {white-space:normal;}

now if only there was an easy to override column widths. this doesn't work because it's overridden by the javascript that sets up the table...
.x-grid-col-1 {width:100%}
ALittleSlow

ALittleSlow wrote on 05/19/08 5:28 PM

Nice quick tip. Thanks.

I'm not sure why

.x-grid-row td {white-space:normal;}

didn't work "straight off", though I'm sure it has to do with the cascade order. Adding an ID specifier (for the form ID in my case) made it work:

#frmMyForm .x-grid-row td {white-space:normal;}
PJ

PJ wrote on 08/01/08 12:43 PM

THANK YOU ALittleSlow! I've spent HOURS googling trying to figure out how to wrap text in cfgrid and it ONLY brings me to flash (not html) cfgrid various methods I couldn't figure out how to apply or just didn't seem to work. Mike's little style snippet and your form ID variant works, finally!!

Write your comment



(it will not be displayed)





About Michael Sprague

Mike is a Web developer and manager from Central New York, specializing in ColdFusion, CSS, JavaScript, and Ajax development. More ...

Categories

Monthly Archives

Favorite Bloggers

Web Resources