Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3722

Grid Row childAttributes calculation ignores colspan and rowspan defined on Cell

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 8.5.0
    • 8.0.5
    • None
    • Security Level: Jimmy
    • None
    • None

      Steps to Reproduce

      Run fiddle
      http://zkfiddle.org/sample/1lc8tpa/1-colspan-rowspan-not-count-hidden-columns
      See 'may' column

      Current Result

      colspan and rowspan defined at cell level are ignored when calculating childAttrs (such as visible) which cause a mismatch between the column and the content
      row / header based colspan and rowspan are calculated, but are deprecated since 8.0.5

      Expected Result

      cell level collspan and rowspan should be used to increment the column index when calculating the content

      Debug Info

      https://github.com/zkoss/zk/blob/master/zul/src/archive/web/js/zul/grid/Row.js#L190-L198

      Root Cause

      Workaround

      for ZK 8.0.5
      add calculation for zul.wgt.Cell based colspan and rowspan

      <script><![CDATA[
      		zk.afterLoad('zul.grid', function() {
      			var xRow = {};
      			zk.override(zul.grid.Row.prototype, xRow ,{
      				_childAttrs: function (child, index) {
      					var realIndex = index, span = 1;
      					//START WORKAROUND
      					var child = this.firstChild;
      					while(child && child.getChildIndex()<index){
      						if(child instanceof zul.wgt.Cell ){
      							realIndex += (child.getColspan()-1);
      						}
      						child = child.nextSibling;
      					}
      					var row = this.parent.firstChild;
      					while(row.nextSibling && row != this){
      						child = row.firstChild;
      						while(child && child.getChildIndex()<index){
      							if(child instanceof zul.wgt.Cell ){
      								if((child.getRowspan()-1)>=(this.getChildIndex()-row.getChildIndex())){
      									realIndex += 1;
      								}
      							}
      							child = child.nextSibling;
      						}
      						row = row.nextSibling;
      					}
      					//END WORKAROUND
      					if (this._spans) {
      						for (var j = 0, k = this._spans.length; j < k; ++j) {
      							if (j == index) {
      								span = this._spans[j];
      								break;
      							}
      							realIndex += this._spans[j] - 1;
      						}
      					}
      					var visible, hgh, align, valign,
      						grid = this.getGrid();
      					if (grid) {
      						var cols = grid.columns;
      						if (cols) {
      							if (realIndex < cols.nChildren) {
      								var col = cols.getChildAt(realIndex);
      								
      								visible = col.isVisible() || (grid._model && !this._loaded) ? '' : 'display:none;';
      								hgh = col.getHeight();
      								align = col.getAlign();
      								valign = col.getValign();
      							}
      						}
      					}
      					var style = this.domStyle_({visible: 1, width: 1, height: 1}),
      						isDetail = zk.isLoaded('zkex.grid') && child.$instanceof(zkex.grid.Detail);
      					if (isDetail) {
      						var wd = child.getWidth();
      						if (wd)
      							style += 'width:' + wd + ';';
      					}
      					if (visible || hgh || align || valign) {
      						style += visible;
      						if (hgh)
      							style += 'height:' + hgh + ';';
      						if (align)
      							style += 'text-align:' + align + ';';
      						if (valign)
      							style += 'vertical-align:' + valign + ';';
      					}
      					var clx = isDetail ? child.$s('outer') : this.$s('inner'),
      						attrs = '';
      					if (span !== 1)
      						attrs += ' colspan="' + span + '"';
      					if (this._nowrap)
      						attrs += ' nowrap="nowrap"';
      					if (style)
      						attrs += ' style="' + style + '"';
      					return attrs + ' class="' + clx + '"';
      				}
      			});//zk.override
      		});//zk.afterLoad
      	]]></script>
      

            wenninghsu wenninghsu
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours
                7h