0% found this document useful (0 votes)
65 views13 pages

Table Filter

This document discusses how to implement filtering of a table using the TableFilter Java class in Web Dynpro. It provides steps for the default implementation, including adding the TableFilter class, creating nodes to hold all data and filtered data, associating filters to columns, and coding the filter action. It also notes limitations of the default implementation and provides tips for improving it, such as filtering icons according to their legend and updating the all data node when table data changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views13 pages

Table Filter

This document discusses how to implement filtering of a table using the TableFilter Java class in Web Dynpro. It provides steps for the default implementation, including adding the TableFilter class, creating nodes to hold all data and filtered data, associating filters to columns, and coding the filter action. It also notes limitations of the default implementation and provides tips for improving it, such as filtering icons according to their legend and updating the all data node when table data changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

Table Filter.......................................................................................................................

1
Table Filter...................................................................................................................1
Filtering capabilities:...................................................................................................2
Quick Steps for default implementation:.........................................................................2
Step 1: Add TableFilter...............................................................................................2
Step 2: Create Nodes...................................................................................................3
Step 3: Associate Filter to Column..............................................................................4
Step 4: Create Table Filter in Context View...............................................................4
Step 5: Create filter Action..........................................................................................6
Step 6: Code Filter Action...........................................................................................6
Step 7: Code wdDoModifyView.................................................................................7
Step 8: Add explanation:.............................................................................................7
Remarks about Table Filter default implementation.......................................................8
Table Filter does not update the all data node :...........................................................8
Dynamic table..............................................................................................................8
What the Table Filter does not work for......................................................................9
Improving the default implementation............................................................................9
Filtering Icons..............................................................................................................9
Filtering Drop down:.................................................................................................11
Updating the all data node from the table node.........................................................12
Tips & Trick:.............................................................................................................13

Table Filter
Table Filter
The TableFilter is a java class. It filters the column of a table according the filter value
located at the top of a column. It can be implemented in few steps.

1
Here is an example of filtering using the TableFilter java class:

When the TableFilter’s filter action is triggered, the filter method passes two nodes. The
first node contains all the data and the table’s node, the node that show the data. The
TableFilter populates the table node from the all data node according the filter values.
Filtering is done for each filter value of each column , only the row matching all the
filters are shown.

Filtering capabilities:
The table filter has the following capabilities:
Strings : if the filter value is a “a” it returns any fields that as a “a” , what ever is the
position of the a in the string and does not makes difference between upper case and
lower case. It also accepts the # (exclude) or (=) include sign in first position.
Numeric values , dates, times: It filter for the exact value, a range(~) , include(=) ,
exclude(#) sign. The include or exclude sign should be in first position.
For range “~100”, gives the values up to 100 included;”1~100” gives all values between
1 and 100 , 1 and 100 included;” 100~” gives all the values about 100 , 100 included
Boolean values: Booleans can be filter using include (=) or exclude (#).
Icons: Icons can be filtered according there legend. Legend is language dependant.
Icons legend can be shown as a tool tip of the icon.

Quick Steps for default implementation:


First we will speak about the quick default implantation. Then we will see how we can
improve the default implementation.
The default implementation assumes that the table node is a value node and drop down
and icons if any in the table are not filtered.

Step 1: Add TableFilter


Add the table filter to the package.

2
Step 2: Create Nodes
The filter table needs 3 nodes (see figure below) One table node, on filter node, one all
data node. All these nodes should be under the root node context. The All data node that
contains always all the data , it is called in the figure below “sourceNode” . The
“FilterNode” contains the filter values. The attributes of the SourceNode & TableNode
are identical. They have the same attribute names; and the attributes with the same name
are of the same type. The Filter node is of cardinality 1,1 and contains the values of the
filter , one attribute per column you want to filter. All the filter attributes are of type
string.

3
Step 3: Associate Filter to Column
Each column that you want to filter must have a filter.

Step 4: Create Table Filter in Context View


In the view controller create a context attribute “TableFilter” . Its type is TableFilter:

The details steps to do it are :

The type is chosen by selecting the “…” button

4
Then select button Java Native Type & Browse button:

5
Step 5: Create filter Action
Go to the Actions tab and create an action with the name filter.

Step 6: Code Filter Action

Go to the implementation tab and under the onActionFilter() put the following code:
public void
onActionfilter(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent
)
{
//@@begin onActionfilter(ServerEvent)

wdContext.currentContextElement().getTableFilter().filter(wdContext.node
Source(), wdContext.nodeTable(),null);
//@@end
}

6
Step 7: Code wdDoModifyView

Switch to the method wdDoModifyView and enter the following source code:
public static void wdDoModifyView(IPrivateTableFilterCV wdThis,
IPrivateTableFilterCV.IContextNode wdContext,
com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView

if (firstTime ) {

IWDTable table = (IWDTable) view.getElement("Table");


wdContext.currentContextElement().setTableFilter(
new TableFilter(table, wdThis.wdGetFilterAction(),
wdContext.nodeSource(),null));
}

//@@end
}

“Table” is the id of the UI table :

At the first time wdDoModifyView initialize the table filter. The constructor of the table
filter for each column finds the associated filter and the needed comparator to perform
the column filtering.

Step 8: Add explanation:


Add an explanation of the filter’s capabilities above you table :

7
The text could be like this:
Character fields are filtered for any character in the field, include =, exclude #. Numeric ,
Date fields can be filtered for exact value, range ~ , exclude #. Check boxes can be
filtered for include = or exclude #. Icon by legend.

Remarks about Table Filter default implementation


Table Filter does not update the all data node :
If the table is updatable, and some data are updated, or some rows are added or deleted,
the TableFilter does not update the all data node, the “sourceNode” in our example.. The
DC has to do the update.

The Source Node (all data) and the Table Node should be under the root context.
If you want the table node to update the source node, see paragraph “Enhancing the
default implementation if the all data node needs to be update from the table node.”

8
Dynamic table
If the number of columns of a table changes during a application session, for example a
table that has it columns built dynamically and changed during the session, the table
filter as to be recreated , so we can put a extra condition to recreate the Table Filter.
For example now we look also at a ToRefresh flag and the code becomes:
boolean b= wdContext.currentContextElement().getToRefresh();
if (firstTime |b ) {
IWDTable table = (IWDTable) view.getElement("Table_1");
wdContext.currentContextElement().setTableFilter(
new TableFilter(table, wdThis.wdGetFilterAction(),
null));
wdContext.currentContextElement().setToRefresh(false);
}

What the Table Filter does not work for.


Currently the table filter does not work for :
-hierarchical table.
- non-singleton child node attributes. This Table Filter sorts columns which are directly
bound to an attribute of the table's root context node. Attributes of non-singleton child
nodes of this node, which were displayed in the same table, are not filterable.

Improving the default implementation


Filtering Icons
A icon is filtered according its legend., you need in the all data node and the table node a
attribute for the legend icons (legend icon are language dependent and will have to be
translated) so in the TableFilter constructor the last parameter is a hashtable that
indicates the mapping between the icon column ids and the icon legend attribute.
The constructor becomes:
if (firstTime ) {
// mapping of the icon column to the legend column
Hashtable hash=new Hashtable(); hash.put("Icon","IconLegend");
// table constructor has the hash table as a parameter
IWDTable table = (IWDTable) view.getElement("Table");
wdContext.currentContextElement().setTableFilter(
wdContext.currentContextElement().setTableFilter(

9
new TableFilter(table, wdThis.wdGetFilterAction(),
(IWDNode)wdContext.nodeSource(),hash));
}

The logic is explained in the figure below.

The result is:

10
Warning : never make a column legendIcon in the table. The reason is that at
initialization of the TableFilter will automatically associate the legendIcon column with
the legendIcon attribute. The icon mapping given by the hashtable will be disregarded.

Filtering Drop down:


Since drop down shows text but the column value is a key, the filtering must be done the
same way the icon filtering is done. This means that at the initialization, the hashtable

11
Updating the all data node from the table node.

If the table has be updated or if some rows have been added or deleted. The All data node
needs to be updated from the table node. TableFilter has currently two methods that are
doing that. To update the AllDataNode from the table node , each method has to know
what attribute is the unique identifier of the element (this identifier cannot be the element
index)

The method to update is:


public void updateAllDataNodeElment( IWDNode sourceNode, IWDNode
targetNode, String attributeRowId, boolean addRowOnFly);

String attributeRowId : is the attribute name that uniquely identify the rowed, this
attribute is of type String.
Boolean addRowonFly : if a row has been added in the table not only the updated
existing row will be updated in AllDataNode but if a row has been created, if the falg is
set to true a new element is created in the AllDataNode.

The method to delete is:

12
public void deleteAllDataNodeElement(IWDNode sourceNode, IWDNode
targetNode, String attributeRowId, ArrayList idsToDelete)

String attributeRowId : is the attribute name that uniquely identify the row, this attribute
is of type String.
ArrayList idsToDelete: contains a list of the unique row identifier to
delete.

Tips & Trick:


If the data of the AllDataNode are not changed:
If you initiate the TableFilter with the AllDataNode fully populated , and the data are
not changed , when using the filter action, you can pass a null instead of a the
AllDataNode, the method will retrieve the data from the AllDataNode you pass at the
initialization. Or the last time you passed it through the filter action.

13

You might also like