Uploaded image for project: 'ZK Pivottable'
  1. ZK Pivottable
  2. ZKPVT-4

Customize column size doesn't work correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 1.0.0
    • None
    • None

      Define getColumnSize() in custom PivotRenderer, the actual output did not present as desired.
      Sample code from pivottable-demo in SimplePivotConfigurator.java:

      @Override
      public PivotRenderer getRenderer() {
      	return new PivotRenderer() {
      		private DecimalFormat _fnf = new DecimalFormat("##,###.00");
      		private DecimalFormat _nnf = new DecimalFormat("##,###");
      		@Override
      		public String renderCell(Object data, Pivottable table,
      				PivotHeaderContext rowContext,
      				PivotHeaderContext columnContext, PivotField dataField) {
      			return data == null ? "" :
      				data instanceof Integer ? _nnf.format(data) : _fnf.format(data);
      		}
      
      		@Override
      		public String renderField(Object data, Pivottable table,
      				PivotField field) {
      			return field.getArea() == PivotField.AREA_DATA ?
      					field.getTitle() : String.valueOf(data);
      		}
      
      		@Override
      		public String renderSubtotalField(Object data, Pivottable table,
      				PivotField field, Calculator calculator) {
      			String calLabel = Texts.capitalize(calculator.getType());
      			String dataLabel = data == null ? "Null" : data.toString();
      			return dataLabel + " " + calLabel;
      		}
      
      		@Override
      		public String renderGrandTotalField(Pivottable table, PivotField field) {
      			if (field == null) return "Grand Total";
      			return "Grand Total of " + field.getTitle();
      		}
      
      		@Override
      		public int getColumnSize(Pivottable table, PivotHeaderContext columnContext, PivotField field) {
      			int columnSize = 100; //default column size
      			if(columnContext.isGrandTotal() && field != null) {
      				columnSize = 150;
      			} else {
      				if("Customer".equals(field.getTitle()))
      					columnSize = 300;
      				if("Price".equals(field.getTitle()))
      					columnSize = 90;
      			}
      			return columnSize;
      		}
      
      		@Override
      		public int getRowSize(Pivottable table,
      				PivotHeaderContext rowContext, PivotField field) {
      			return 20;
      		}
      		
      	};
      	//return null; // use default renderer
      }
      

            SimonPai SimonPai
            vincentjian vincentjian
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: