ColumnFormatter class
This class contains methods used to format a table's columns. It is limited by the support cross-browser HTML support for column formatting.
class ColumnFormatter {
dart_html.Element columnGroup;
HtmlTable _table;
/**
* Adds a style to the specified column.
*
* @param col the col to which the style will be added
* @param styleName the style name to be added
* @see UiObject#addStyleName(String)
* @throws IndexOutOfBoundsException
*/
void addStyleName(int col, String styleName) {
UiObject.manageElementStyleName(ensureColumn(col), styleName, true);
}
/**
* Get the col element for the column.
*
* @param column the column index
* @return the col element
*/
dart_html.Element getElement(int column) {
return ensureColumn(column);
}
/**
* Gets the style of the specified column.
*
* @param column the column to be queried
* @return the style name
* @see UiObject#getStyleName()
* @throws IndexOutOfBoundsException
*/
String getStyleName(int column) {
return UiObject.getElementStyleName(ensureColumn(column));
}
/**
* Gets the primary style of the specified column.
*
* @param column the column to be queried
* @return the style name
* @see UiObject#getStylePrimaryName()
* @throws IndexOutOfBoundsException
*/
String getStylePrimaryName(int column) {
return UiObject.getElementStylePrimaryName(ensureColumn(column));
}
/**
* Removes a style from the specified column.
*
* @param column the column from which the style will be removed
* @param styleName the style name to be removed
* @see UiObject#removeStyleName(String)
* @throws IndexOutOfBoundsException
*/
void removeStyleName(int column, String styleName) {
UiObject.manageElementStyleName(ensureColumn(column), styleName, false);
}
/**
* Sets the style name associated with the specified column.
*
* @param column the column whose style name is to be set
* @param styleName the new style name
* @see UiObject#setStyleName(String)
* @throws IndexOutOfBoundsException
*/
void setStyleName(int column, String styleName) {
UiObject.setElementStyleName(ensureColumn(column), styleName);
}
/**
* Sets the primary style name associated with the specified column.
*
* @param column the column whose style name is to be set
* @param styleName the new style name
* @see UiObject#setStylePrimaryName(String)
* @throws IndexOutOfBoundsException
*/
void setStylePrimaryName(int column, String styleName) {
UiObject.setElementStylePrimaryName(ensureColumn(column), styleName);
}
/**
* Sets the width of the specified column.
*
* @param column the column of the cell whose width is to be set
* @param width the cell's new width, in percentage or pixel units
* @throws IndexOutOfBoundsException
*/
void setWidth(int column, String width) {
Dom.setElementProperty(ensureColumn(column), "width", width);
}
/**
* Resize the column group element.
*
* @param columns the number of columns
* @param growOnly true to only grow, false to shrink if needed
*/
void resizeColumnGroup(int columns, bool growOnly) {
// The colgroup should always have at least one element. See
// prepareColumnGroup() for more details.
columns = dart_math.max(columns, 1);
int num = columnGroup.children.length;
if (num < columns) {
for (int i = num; i < columns; i++) {
columnGroup.append(new dart_html.TableColElement());
}
} else if (!growOnly && num > columns) {
for (int i = num; i > columns; i--) {
columnGroup.lastChild.remove();
}
}
}
dart_html.Element ensureColumn(int col) {
_table.prepareColumn(col);
prepareColumnGroup();
resizeColumnGroup(col + 1, true);
return columnGroup.children[col];
}
/**
* Prepare the colgroup tag for the first time, guaranteeing that it exists
* and has at least one col tag in it. This method corrects a Mozilla issue
* where the col tag will affect the wrong column if a col tag doesn't exist
* when the element is attached to the page.
*/
void prepareColumnGroup() {
if (columnGroup == null) {
columnGroup = new dart_html.Element.tag("colgroup");
Dom.insertChild(_table.tableElem, columnGroup, 0);
columnGroup.append(new dart_html.TableColElement());
}
}
}
Properties
Element columnGroup #
dart_html.Element columnGroup
Methods
void addStyleName(int col, String styleName) #
Adds a style to the specified column.
@param col the col to which the style will be added @param styleName the style name to be added @see UiObject#addStyleName(String) @throws IndexOutOfBoundsException
void addStyleName(int col, String styleName) {
UiObject.manageElementStyleName(ensureColumn(col), styleName, true);
}
Element ensureColumn(int col) #
dart_html.Element ensureColumn(int col) {
_table.prepareColumn(col);
prepareColumnGroup();
resizeColumnGroup(col + 1, true);
return columnGroup.children[col];
}
Element getElement(int column) #
Get the col element for the column.
@param column the column index @return the col element
dart_html.Element getElement(int column) {
return ensureColumn(column);
}
String getStyleName(int column) #
Gets the style of the specified column.
@param column the column to be queried @return the style name @see UiObject#getStyleName() @throws IndexOutOfBoundsException
String getStyleName(int column) {
return UiObject.getElementStyleName(ensureColumn(column));
}
String getStylePrimaryName(int column) #
Gets the primary style of the specified column.
@param column the column to be queried @return the style name @see UiObject#getStylePrimaryName() @throws IndexOutOfBoundsException
String getStylePrimaryName(int column) {
return UiObject.getElementStylePrimaryName(ensureColumn(column));
}
void prepareColumnGroup() #
Prepare the colgroup tag for the first time, guaranteeing that it exists and has at least one col tag in it. This method corrects a Mozilla issue where the col tag will affect the wrong column if a col tag doesn't exist when the element is attached to the page.
void prepareColumnGroup() {
if (columnGroup == null) {
columnGroup = new dart_html.Element.tag("colgroup");
Dom.insertChild(_table.tableElem, columnGroup, 0);
columnGroup.append(new dart_html.TableColElement());
}
}
void removeStyleName(int column, String styleName) #
Removes a style from the specified column.
@param column the column from which the style will be removed @param styleName the style name to be removed @see UiObject#removeStyleName(String) @throws IndexOutOfBoundsException
void removeStyleName(int column, String styleName) {
UiObject.manageElementStyleName(ensureColumn(column), styleName, false);
}
void resizeColumnGroup(int columns, bool growOnly) #
Resize the column group element.
@param columns the number of columns @param growOnly true to only grow, false to shrink if needed
void resizeColumnGroup(int columns, bool growOnly) {
// The colgroup should always have at least one element. See
// prepareColumnGroup() for more details.
columns = dart_math.max(columns, 1);
int num = columnGroup.children.length;
if (num < columns) {
for (int i = num; i < columns; i++) {
columnGroup.append(new dart_html.TableColElement());
}
} else if (!growOnly && num > columns) {
for (int i = num; i > columns; i--) {
columnGroup.lastChild.remove();
}
}
}
void setStyleName(int column, String styleName) #
Sets the style name associated with the specified column.
@param column the column whose style name is to be set @param styleName the new style name @see UiObject#setStyleName(String) @throws IndexOutOfBoundsException
void setStyleName(int column, String styleName) {
UiObject.setElementStyleName(ensureColumn(column), styleName);
}
void setStylePrimaryName(int column, String styleName) #
Sets the primary style name associated with the specified column.
@param column the column whose style name is to be set @param styleName the new style name @see UiObject#setStylePrimaryName(String) @throws IndexOutOfBoundsException
void setStylePrimaryName(int column, String styleName) {
UiObject.setElementStylePrimaryName(ensureColumn(column), styleName);
}
void setWidth(int column, String width) #
Sets the width of the specified column.
@param column the column of the cell whose width is to be set @param width the cell's new width, in percentage or pixel units @throws IndexOutOfBoundsException
void setWidth(int column, String width) {
Dom.setElementProperty(ensureColumn(column), "width", width);
}