:: Forum >>

How to get cell width

Im currently rendering the contents of a ActiveWidgets Grid to an HTML table for our users to print out.

To set the column widths i set include the style tag like follows
<style>
.active-column-0 {width:XXpx}
</style>

... however, when looping through my grid to convert it to HTML, I want to check the column widths (because if its set to 0 then I dont want to render that column in the HTML table).

Can someone point out the syntax for getting the column width of a cell? (i use both version 1 & 2 of the grid).

Thanks in advance
BConnor
Saturday, November 11, 2006
Actually, I ran into something similar.

But I found a better solution than trying to figure out what the column width is.

Ok, let's say you have the following columns.
Firstname, lastname, age, company, phone, email
(and you have CSS for each - all with widths greater than 0.

When you define your grid, you can use:
obj.setColumnIndices([0,1,3,4,5]
This displays all columns EXCEPT "age"

So, now, you want to generate a routine that loops through the grid and converts it to HTML. Do something like:

var cellVal;
for (i=0; i<obj.getRowIndices().length; i++) {
for (j=0; j<obj.getColumnIndices().length; j++) {
cellVal = obj.getCellText(obj.getColumnIndices()[j],obj.getRowIndices()[i]);
}
}

This will read in every cell in every row that is displayed in the grid.

I'm doing most of it from memory from a page I built. I can you the source if you send me an email (dafweg69@yahoo.com).

I use this method for two reasons. 1) Because eventually I might want to display additional columns and the CSS will already be defined. And, 2) because it will always return the data in the grid that is displayed (so I never have to change this code if I make additions to the grid. I currently use it to read the grid and general an HTML print-preview screen as well as initiate an ActiveX control that opens up MS Excel and populates a spreadsheet

I can help more if you want. Oh, I know this works for Version 2 of AW, I don't have experience with version 1 of AW
Carl
Sunday, November 12, 2006

This topic is archived.


Back to support forum

Forum search