COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
17
When user edits a cell in the data table (or row header table and column header table),
PivotEditingProvider will find the rows behind the cell and change values for all the rows. You
can also add a button to your user interface which will call addRow or removeRow method of
PivotEditingProvider if user needs to add and remove rows from the original table model.
Date Calculation and Auto-update
The calculation from the data in the original table model to the data displayed in the pivot
table is a complex process. It is done in PivotTableModel#calculate() method. If the original table
model has a huge number of rows, calculate() could take several minutes or even longer.
Although in most cases, pivot table is used to do static data analysis. However, we notice
many customers use it to do real-time data analysis. That is the data in the original table model
changes constantly. If every change requires the calculate() to be called to update the display, it
is certainly not acceptable. To solve this problem, we introduce a flag in PivotDataModel. If you
call PivotDataModel#setAutoUpdate(true), we will listen to the TableModelEvent fired in the
original table model and update the pivot data incrementally. The result is instead taking a few
minutes to do calculate(), it will only take a few seconds to when a row in the original table
model is added, deleted or modified. If the event is a large scale event such as
tableDataChanged or tableStructureChanged, we will still call calculate(). So if you should fire a
few small scale events, please do that instead of firing one large scale event. Saying that, you
many need to do some experiments in order to find out the best solution. For example,
calculate() takes one minute and each row updated event takes 1 second. If 900 out of 1000
rows are updated at one time, you probably should fire tableDataChanged instead of firing 900
tableRowUpdated events because 1 minute is less than 900 seconds.
Filtering
We already mentioned user can click on the filter button on the fields (except data field) to
uncheck the value from the CheckBoxList popup to do filtering. There is of course one way to
filter data. However this filtering is done after PivotDataModel processed all the data. As you
may know, if you have a huge data, PivotDataModel’s calculate() method will spend a lot of time
to read and calculate the pivot data. In the other word, the user filtering way doesn’t help to
relieve the burden on PivotDataModel at all.
We would like to introduce a class called FilterableTableModel, a class in JIDE Grids, to
combine use with PivotDataModel. Here is how it works.
FilterableTableModel filterModel = new FilterableTableModel(tableModel)
filterModel.addFilter(…);
filterModel.refresh();
PivotDataModel pivotModel = new PivotDataModel(filterModel);
As you can see, instead of passing the tableModel, which is huge, directly to
PivotDataModel, we piped it to FilterableTableModel first. You can add many filters to
FilterableTableModel. The refresh() method will filter away all unnecessary rows so that
PivotDataModel sees a table model which has much less rows. A typical use case is to use fitler
to filter away incomplete or obviously wrong data. People sometimes called it data cleansing.