Author: pkawiak
Date: 2008-09-22 05:21:07 -0400 (Mon, 22 Sep 2008)
New Revision: 10522
Modified:
trunk/ui/extendedDataTable/src/main/java/org/richfaces/component/ExtendedDataTableState.java
trunk/ui/extendedDataTable/src/main/java/org/richfaces/renderkit/AbstractExtendedTableRenderer.java
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTable.js
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableHeader.js
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js
trunk/ui/extendedDataTable/src/main/templates/org/richfaces/htmlExtendedDataTable.jspx
trunk/ui/extendedDataTable/src/test/java/org/richfaces/renderkit/AbstractExtendedTableRendererTest.java
Log:
RF-4505, allowing percentage column widths
Modified:
trunk/ui/extendedDataTable/src/main/java/org/richfaces/component/ExtendedDataTableState.java
===================================================================
---
trunk/ui/extendedDataTable/src/main/java/org/richfaces/component/ExtendedDataTableState.java 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/main/java/org/richfaces/component/ExtendedDataTableState.java 2008-09-22
09:21:07 UTC (rev 10522)
@@ -269,7 +269,7 @@
private String getDefaultColumnSize(UIComponent column){
String widthStr = (String) column.getAttributes().get("width");
- return formatWidth((widthStr == null || widthStr.length() == 0) ? DEFAULT_WIDTH :
widthStr);
+ return (widthStr == null) ? DEFAULT_WIDTH : widthStr;
}
public String getColumnSize(UIComponent column){
@@ -280,7 +280,7 @@
String colId = column.getId().toUpperCase();
for (String val : widths){
if (val.toUpperCase().startsWith(colId+"-")){
- return formatWidth(val.split("-")[1]);
+ return val.split("-")[1];
}
}//for
}
Modified:
trunk/ui/extendedDataTable/src/main/java/org/richfaces/renderkit/AbstractExtendedTableRenderer.java
===================================================================
---
trunk/ui/extendedDataTable/src/main/java/org/richfaces/renderkit/AbstractExtendedTableRenderer.java 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/main/java/org/richfaces/renderkit/AbstractExtendedTableRenderer.java 2008-09-22
09:21:07 UTC (rev 10522)
@@ -121,10 +121,6 @@
if (col.isRendered()) {
writer.startElement("col", table);
String colWidth = table.getColumnSize(col);
- if (Integer.valueOf(colWidth) < Integer
- .valueOf(MIN_COLUMN_WIDTH)) {
- colWidth = MIN_COLUMN_WIDTH;
- }
writer.writeAttribute("width", colWidth, null);
writer.endElement("col");
}
@@ -165,7 +161,7 @@
headerClass, null);
writer.endElement("th");
}
-
+ writer.endElement("tr");
if (header != null) {
writer.endElement("tr");
@@ -720,8 +716,7 @@
*/
protected void encodeRowId(FacesContext context, ResponseWriter writer,
UIDataTable table, int rowId) throws IOException {
- String[] ownersId = table.getClientId(context).split(":");
- String ownerId = ownersId[0] + ":" + ownersId[1];
+ String ownerId = table.getBaseClientId(context);
getUtils().writeAttribute(writer, "id", ownerId + ":n:" +
rowId);
}
Modified:
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTable.js
===================================================================
---
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTable.js 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTable.js 2008-09-22
09:21:07 UTC (rev 10522)
@@ -175,7 +175,9 @@
},
OnWindowResize: function(event) {
- this.updateLayout();
+ if (this.table) {
+ this.updateLayout();
+ }
},
getColumnsNumber: function() {
return this.columnsNumber;
@@ -297,7 +299,7 @@
return sd.offsetWidth - sd.clientWidth;
},
validateColumnsWidth: function(columns,excessWidth) {
- var i=1;
+ var i=0;
var endIndex = columns.length-1;
while ((i < endIndex) && (excessWidth > 0)) {
if (ClientUILib.isIE) {
@@ -355,10 +357,19 @@
var footerHeight = this.getFooterHeight();
var columnsNumber = this.getColumnsNumber();
-
var visibleHeaderWidth = this.header.getVisibleWidth();
var scrollbarWidth = scrollingDiv.getElement().offsetWidth -
scrollingDiv.getElement().clientWidth;
- var maxAllowedWidth = this.mainDiv.getWidth() - scrollbarWidth;
+ var maxAllowedWidth = mainDivWidth - scrollbarWidth;
+ for (var i=0; i < columnsNumber-1; i++) {
+ if (this.header.isColumnWidthPercentage(i)) {
+ //change percents into pixels
+ var val = this.header.getColumn(i).width;
+ val = (val.substr(0, val.length-1)*1)/100;
+ var width = maxAllowedWidth*val;
+ this.header.setColumnWidth(i, width);
+ this.setColumnWidth(i, width);
+ }
+ }
var excessWidth = this.header.getVisibleWidth() - maxAllowedWidth - 1;
if (excessWidth > 0) {
this.validateColumnsWidth(cols,excessWidth);
@@ -368,8 +379,7 @@
var newHeight = mainDivHeight - header.getHeight() - footerHeight - 2;
newHeight -= this.header.getCaptionHeight();
scrollingDiv.setStyle('height:'+ newHeight +'px;');
- var l = headerChildren.length;
- for (var i=0; i < l-1; i++) {
+ for (var i=0; i < columnsNumber-1; i++) {
var headerChild = headerChildren[i];
Utils.DOM.Event.removeListeners(headerChild);
Utils.DOM.Event.observe(headerChild,'mouseover',this.header.eventHeaderCellMouseOver);
Modified:
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableHeader.js
===================================================================
---
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableHeader.js 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableHeader.js 2008-09-22
09:21:07 UTC (rev 10522)
@@ -103,6 +103,13 @@
getColumns: function() {
return this.cols;
},
+ getColumn: function(index) {
+ if (this.isValidColumnNumber(index)) {
+ return this.cols[index];
+ }else{
+ return null;
+ }
+ },
getColumnCells: function() {
return this.columnCells;
},
@@ -121,8 +128,12 @@
}
},
+ isValidColumnNumber: function(columnNumber) {
+ return ((columnNumber < this.getColumnsNumber()) && (columnNumber
>=0))
+ },
+
getColumnWidth: function(columnNumber) {
- if ((columnNumber < this.getColumnsNumber()) && (columnNumber >=0)) {
+ if (this.isValidColumnNumber(columnNumber)) {
var col = this.getColumnCells()[columnNumber];
if (col.offsetWidth != null) {
return col.offsetWidth;
@@ -135,6 +146,20 @@
}
},
+ isColumnWidthPercentage: function(columnNumber) {
+ if (this.isValidColumnNumber(columnNumber)) {
+ var col = this.getColumns()[columnNumber];
+ var width = col.width;
+ if ((!Object.isNumber(width)) && (width.indexOf('%') != -1))
{
+ return true;
+ }else{
+ return false;
+ }
+ }else{
+ return null;
+ }
+ },
+
getHeightWithoutFacets: function() {
return this.headerRow.getHeight() + this.filterRow.getHeight();
},
Modified:
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js
===================================================================
---
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js 2008-09-22
09:21:07 UTC (rev 10522)
@@ -284,7 +284,7 @@
if(!groupingExists) { //simple listener binding
if(this.options.selectionMode != "none") {
for(var i = 0; i < this.rowCount; i++) {
- var arr = nrows[i].id.split(this.prefix)[1].split(":");
+ var arr = nrows[i].id.split(":");
rowIndex = Number(arr[arr.length-1]);
this.addListener(nrows[i], rowIndex);
}
@@ -323,7 +323,7 @@
lastGroupId = groupId;
} else {
if(this.options.selectionMode != "none") {
- var arr =
nrows[i].id.split(this.prefix)[1].split(":");
+ var arr = nrows[i].id.split(":");
rowIndex = Number(arr[arr.length-1]);
this.addListener(nrows[i], rowIndex);
}
@@ -413,7 +413,8 @@
var range, rowIndex;
var activeRow = this.activeRow;
var noDefault = false;
- this.firstIndex = Number($(this.prefix +
":n").rows[0].id.split(this.prefix)[1].split(":")[2]);;
+ var arr = $(this.prefix + ":n").rows[0].id.split(":");
+ this.firstIndex = Number(arr[arr.length-1]);
switch (event.keyCode || event.charCode) {
case Event.KEY_UP:
if (this.inFocus && activeRow != null) {
@@ -506,7 +507,8 @@
var range;
if ( event.shiftKey && !event.ctrlKey && !bSingleSelection &&
!event.altKey) {
- this.firstIndex = Number($(this.prefix +
":n").rows[0].id.split(this.prefix)[1].split(":")[2]);;
+ var arr = $(this.prefix + ":n").rows[0].id.split(":");
+ this.firstIndex = Number(arr[arr.length-1]);
this.selectionFlag = "x";
if(!this.shiftRow) {
this.shiftRow = this.activeRow;
Modified:
trunk/ui/extendedDataTable/src/main/templates/org/richfaces/htmlExtendedDataTable.jspx
===================================================================
---
trunk/ui/extendedDataTable/src/main/templates/org/richfaces/htmlExtendedDataTable.jspx 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/main/templates/org/richfaces/htmlExtendedDataTable.jspx 2008-09-22
09:21:07 UTC (rev 10522)
@@ -62,12 +62,12 @@
<div
id="#{clientId}"
- class="extdt-maindiv"
- style="width:#{component.attributes['width']};
height:#{component.attributes['height']}"
+ class="extdt-maindiv rich-extdt-maindiv"
+ style="#{component.attributes['style']};width:#{component.attributes['width']};height:#{component.attributes['height']}"
<div id="#{clientId}:od" class="extdt-outerdiv"
- style="width:100%; height:100%;"
+ style="width:100%; height:100%;overflow: hidden;"
<div id="#{clientId}:dataTable_indicator"
class="drgind_fly drgind_default drag_indicator" style="display:
none;" >
<f:call name="encodeNamespace" />
@@ -98,10 +98,7 @@
<td colspan="#{columnsCount}" style="padding: 0px;">
<div id="#{clientId}:sd" class="extdt-content"
style="height:50px;width:100%;">
<table id="#{clientId}:n" width="100%"
- class="extdt-table-layout rich-table
#{component.attributes['styleClass']}"
- style="#{component.attributes['style']}"
- cellpadding="0"
- cellspacing="0"
+ class="extdt-table-layout rich-table
#{component.attributes['styleClass']}"
<f:call
name="utils.encodePassThruWithExclusions">
<f:parameter
value="height,value,name,type,id,class,rows,style,width" />
Modified:
trunk/ui/extendedDataTable/src/test/java/org/richfaces/renderkit/AbstractExtendedTableRendererTest.java
===================================================================
---
trunk/ui/extendedDataTable/src/test/java/org/richfaces/renderkit/AbstractExtendedTableRendererTest.java 2008-09-20
17:57:11 UTC (rev 10521)
+++
trunk/ui/extendedDataTable/src/test/java/org/richfaces/renderkit/AbstractExtendedTableRendererTest.java 2008-09-22
09:21:07 UTC (rev 10522)
@@ -349,7 +349,7 @@
String className = element.getAttributeValue("id");
assertNotNull(className);
- assertEquals("extDT:10:n:0", className);
+ assertEquals("extDT:n:0", className);
}
}