basegridcolumn.lzx
<library>
<class name="basegridcolumn" extends="basecomponent">
<attribute name="text" type="text" value="$once{ this.datapath? this.datapath.xpath : '' }"/>
<attribute name="minwidth" value="10
" type="number"/>
<attribute name="_contentsPackage" value="null
"/>
<attribute name="colwidth" value="${this.width}"/>
<attribute name="ascendsort" value="true
"/>
<attribute name="defaultplacement" type="string" value="content
"/>
<attribute name="placement" value="hcontent
"/>
<attribute name="sortpath" value="
" type="string"/>
<attribute name="datatype" value="string
" type="string"/>
<attribute name="ascendComparator" value="null
"/>
<attribute name="descendComparator" value="null
"/>
<attribute name="hasSort" value="false
" type="boolean"/>
<attribute name="focusable" value="false
"/>
<attribute name="_lineColor" value="black
" type="color"/>
<method name="_applystyle" args="s">
this.setAttribute( '_lineColor' , s.bordercolor );
</method>
<method name="determinePlacement" args="v, p, args">
if ( p == "content" ){
if ( !_contentsPackage ){
this._contentsPackage = [];
}
var a = {};
//need to make a new object here, to make sure that we're not
//(later) assigning to the class attribute
for ( var k in v._instanceAttrs ){
a[ k ] = v._instanceAttrs[ k ];
}
var o = { 'class': v.constructor, attrs: a };
if ( typeof( v._instanceChildren ) != "undefined" ){
o.children = v._instanceChildren;
}
this._contentsPackage.push( o );
//sadly, we really don't need this
v.destroy();
return this;
} else if ( p == "header" ){
return this;
} else if ( p == "gridcontent" ){
return parent.content;
} else {
return super.determinePlacement(v, p, args);
}
</method>
<method name="_getCellForColumn">
if ( !this._contentsPackage ) return null;
var fupdCellBounds = function(ignore=null) {
//'this' points to the grid cell
this.setAttribute('x', this.ownerColumn.x );
this.setAttribute('width', this.ownerColumn.colwidth );
};
var contentspkg = this._contentsPackage;
if ( contentspkg.length == 1 ) {
var o = contentspkg[ 0 ];
var cellargs = o.attrs;
cellargs.ownerColumn = this;
cellargs._updateCellBounds = fupdCellBounds;
return o;
} else {
//there's more than one subview, so we need to pack them up
return { 'class': lz.view,
attrs: {ownerColumn: this, _updateCellBounds: fupdCellBounds},
children: contentspkg };
}
</method>
<method name="_inferSortpath">
if ( !_contentsPackage ) return "";
for ( var i = 0; i < _contentsPackage.length; i++ ){
var attrs = _contentsPackage[ i ].attrs;
if ( attrs[ 'datapath' ] != null ){
return attrs.datapath;
}
}
return "";
</method>
<method name="doSort">
if ( this.sortpath == "" ) return;
var repl = this.parent._getReplicator();
if (repl != null && repl is LzReplicationManager) {
repl.setOrder( this.sortpath , this._getSortorderArg() );
}
this.setAttribute( "ascendsort" , !this.ascendsort );
this.parent._setSortCol( this );
</method>
<method name="init">
if ( this.sortpath == "" ){
this.setAttribute( 'sortpath' , this._inferSortpath() );
}
super.init();
</method>
<method name="_getSortorderArg">
if ( this.ascendsort ){
if ( this.ascendComparator ){
// Debug.write( this.ascendComparator);
return this.ascendComparator;
} else if ( this.datatype == "number" ){
return this._numericAscendingSort;
} else {
return "ascending";
}
} else {
if ( this.descendComparator ){
return this.descendComparator;
} else if ( this.datatype == "number" ){
return this._numericDescendingSort;
} else {
return "descending";
}
}
</method>
<method name="_numericAscendingSort" args="a,b">
var x = Number( a );
var y = Number( b );
//if a variable is NaN, then it won't equal itself
var xisnum = x == x;
var yisnum = y == y;
if ( xisnum == yisnum ){
if ( !xisnum ){
x = a;
y = b;
}
if ( x < y ){
return 1;
} else if ( x == y ){
return 0;
} else {
return -1;
}
} else if ( xisnum ){
return 1;
} else {
return -1;
}
</method>
<method name="_numericDescendingSort" args="a,b">
var x = Number( a );
var y = Number( b );
//if a variable is NaN, then it won't equal itself
var xisnum = x == x;
var yisnum = y == y;
if ( xisnum == yisnum ){
if ( !xisnum ){
x = a;
y = b;
}
if ( x > y ){
return 1;
} else if ( x == y ){
return 0;
} else {
return -1;
}
} else if ( yisnum ){
return 1;
} else {
return -1;
}
</method>
<state applied="${parent.parent.showvlines}">
<view bgcolor="${parent._lineColor}" width="1" x="${parent.x + parent.colwidth + parent.immediateparent.x}" height="${immediateparent.height}" placement="gridcontent" oninit="this.sendInFrontOf( immediateparent.rowparent )" options="ignorelayout"/>
</state>
<doc>
<tag name="shortdesc"><text>An abstract column in a grid.</text></tag>
<text>
<p><classname>basegridcolumn</classname> can be used in
<classname>basegrid</classname>s or <classname>grid</classname>s to
customize the look of both the column header and the row contents for
that column. In cases where a standard column header look is desired,
but the contents may vary, use <classname>gridcolumn</classname>.</p>
<p>The placement of "header" can be used to place nodes in the header
of the grid, and the default placement for the class will place things
in the row. See the example in <classname>basegrid</classname>.</p>
</text>
</doc>
</class>
</library>