0

ZK PivotTable Question

asked 2011-11-19 14:59:10 +0800

estebanz01 gravatar image estebanz01
21

updated 2011-11-19 14:59:21 +0800

Good Morning everyone,

I've got a question about the size of row fields in the pivot table: It's some way to resize that cells?

Grettings

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2011-11-22 03:25:17 +0800

vincentjian gravatar image vincentjian
2245 6

Hi estebanz01,

There are two steps to resize cell witdh.
First, you have to override PivotRenderer.getColumnSize() to customize the cell width.
Here is the sample:

public int getColumnSize(Pivottable table, PivotHeaderContext columnContext, PivotField field) {
       int columnSize = 100; //the default width for all columns, measure in pixel
       if(columnContext.isGrandTotal() && field != null) {
              columnSize = 150;
       } else {
              if("columnTitle1".equals(field.getTitle()))
                     columnSize = 300;
              if("columnTitle2".equals(field.getTitle()))
                     columnSize = 90;
       }
       return columnSize;
}

Second, override default CSS in the zul:
<style>
.z-pivottable-body, .z-pivottable-cell-body {
    border-spacing: 0;
    border: 1px solid red;
    cursor: default;
    width: 0;
}
</style>

link publish delete flag offensive edit

answered 2011-11-28 15:27:15 +0800

estebanz01 gravatar image estebanz01
21

Grettings,

First of all, thanks for your answer. I tried to use the override function without any result.

I create a class that implements the PivotRenderer class, override the function and I call it in the override function doAfterCompose like this:

private Pivottable pivot;
/* other private variables */
private Renderer sizeCols;
/* Operations, Data Values, etc... */
pivot.setPivotRenderer(sizeCols);

And the Rendererer class looks like this:


import org.zkoss.pivot.Calculator;
import org.zkoss.pivot.PivotField;
import org.zkoss.pivot.PivotHeaderContext;
import org.zkoss.pivot.PivotRenderer;
import org.zkoss.pivot.Pivottable;

public class Renderer implements PivotRenderer{

	@Override
	public int getColumnSize(Pivottable table, PivotHeaderContext columnContext, PivotField field){
    	int columnSize = 100;
    	if(columnContext.isGrandTotal() && field != null){
    		columnSize = 150;
    	}
    	else{
    		if("Filas".equals(field.getTitle()))
    			columnSize = 30;
    		if("Columnas".equals(field.getTitle()))
    			columnSize = 50;
    		if("Valores".equals(field.getTitle()))
    			columnSize = 0;
		}
    	return columnSize;
	}

	@Override
	public int getRowSize(Pivottable arg0, PivotHeaderContext arg1,
			PivotField arg2) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String renderCell(Object arg0, Pivottable arg1,
			PivotHeaderContext arg2, PivotHeaderContext arg3, PivotField arg4) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String renderField(Object arg0, Pivottable arg1, PivotField arg2) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String renderGrandTotalField(Pivottable arg0, PivotField arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String renderSubtotalField(Object arg0, Pivottable arg1,
			PivotField arg2, Calculator arg3) {
		// TODO Auto-generated method stub
		return null;
	}
	
}

Thanks again for helping me.

link publish delete flag offensive edit

answered 2011-12-01 10:04:19 +0800

vincentjian gravatar image vincentjian
2245 6

Hi,
Notice my second step, override default CSS in the zul is necessary to let the column width work.

link publish delete flag offensive edit

answered 2012-01-02 22:33:25 +0800

estebanz01 gravatar image estebanz01
21

Hi,

Take a look to my index.zul

<zk>
	<style>
		.z-pivottable-body, .z-pivottable-cell-body{
			border-spacing: 0px;
			border: 1px solid red;
			cursor: default;
			width: 0px;
		}
	</style>
	<label id="etiqueta" style="font-size: 30px; font-weigth: bold"/>
	<window id="mainWin" apply="Tabla.PivotController">
    <pivottable id="pivot" hflex="1">
        <div>Valores</div>
        <div>Columnas</div>
        <div>Filas</div>
    </pivottable>
    </window>
    <separator />
</zk>

That doesn't work. Why?

Thanxs for your answer and interesting.

link publish delete flag offensive edit

answered 2012-01-03 03:52:35 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2012-01-03 03:53:30 +0800

Hi,

Did you upgrade pivottable to stable version?
Please try to upgrade to the stable version and the CSS override is no longer necessary.
BTW, the API changes a lot too but is more easy to use.
If you still have the problem about the column size after upgrading, please post the problem again, thanks.

link publish delete flag offensive edit

answered 2013-05-30 14:14:14 +0800

LuigiFabbri gravatar image LuigiFabbri
46 5

the solutions is

private Renderer sizeCols=new Renderer(); pivot.setPivotRenderer(sizeCols);

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-11-19 14:59:10 +0800

Seen: 715 times

Last updated: May 30 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More