on 01-23-2007 4:46 AM
Hi,
I have a tree within a table(Maaster Column) & i need to implement a search functionality such that a user gives his search criteria in a form & on click of button, the corresponding entry in table is displayed at the first row.
Can someone suggest me so as how to do this...??
Thanks & Regards,
Ankur
Hi all,
I have implemented the search criteria in a simple table successfully.
In case of a simple table I have recursively iterated through the elements & when relevant element is found, I have set the firstvisiblerow & leadselection to the index of that element.
But in the case of tree table, I am facing problem while iterating through the elements & finding the relevant element.Here relevant element would be that for which text matches with the input given by user.
Also, here I have to show the parent expanded, if a child is searched.
If anyone can help me in solving this query.
Thanks & regards,
Ankur
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Context:
node: MyTree
recursive subnode: MySubTree
attribute: Title (string)
attribute: IsExpanded (boolean)
attribute: isLeaf (boolean)
code to search search string searchMe:
private IMyTreeElement searchMyTree( final String searchMe, final IMyTreeNode nMyTree )
{
if ( null == nMyTree )
return null;
for (int i = 0; i < nMyTree.size(); i++)
{
final IMyTreeElement elMyTree = nMyTree.getMyTreeElementAt(i);
final String currTitle = elMyTree.getTitle();
if ( searchMe.equals( currTitle ) )
{
return elMyTree; // found
}
if ( !elMyTree.getIsLeaf() )
{
IMyTreeElement elFoundInChildren = searchMyTree( searchMe, elMyTree.nodeMySubTree() );
if ( null != elFoundInChildren )
{
elMyTree.setIsExpanded( true ); // expand
return elFoundInChildren;
}
}
}
// nothing found
return null;
}
Hi Dzmitry ,
Thanks for your help.
I have a query related to your code.
Your search criteria works very well if i initially manually expand the whole tree (& then close) & then search.
If i search just after the application is started(i.e. without initially expanding the tree), no action take place.
what i get to understand that the elements of node:MyTree are not been initialised until unless onLoadChild actoin is not called.
Correct me if i am wrong.
Advice & Suggestions from all are welcomed.
Kind Regards,
Ankur
"MyTree are not been initialized until unless onLoadChild action is not called"
I see. Yes, this is true.
In such case you probably has to search not in WD Context, but in origin data if it is possible (if it is loaded into memory already, e.g. in some java structure).
Otherwise you may select: either limit searching only on elements already loaded and displayed; or load all the tree on first search.
Hi Dzmitry,
Even i have gone through the idea of loading the treetable initially on page load. Then Search works very fine.
But I have a concern over here.
I have made a method Expand() & calling it in wdDoInit().But calling it in wdDoInit only expands one level hierarchy not lower than that.This is what i have written in wdDoInit():-
//in wdDoInit for initially expanding
if (!element.getLoaded()) {
LoadChildData(element);
element.setLoaded(true);
}
wdThis.Expand(wdContext.nodeOrgUnit(),true);
// method Expand
public void Expand( com.sap.test.tree.view.wdp.IPrivateTreeView.IOrgUnitNode node, boolean expand )
{
//@@begin Expand()
if (node != null) {
node.moveFirst();
do{
try {
node.currentOrgUnitElement().setExpanded(expand);
} catch (RuntimeException e) {
e.printStackTrace();
}
wdThis.ExpandAll(node.nodeChildren(), expand);
}while(node.moveNext() != null);
}
//@@end
}
Hi.
Create Context attribute FirstVisibleRow (integer) and bind corresponding property of the TreeTable to it.
In Search eventhandler you may look up context node (to which is bound the TreeTable) to find the required element.
Then calculate its index (look in the <a href="/people/valery.silaev/blog/2005/06/20/master-of-columns-part-ii of Columns, p2</a> blog)
Finnally, set the FirstVisibleRow attribute to that index.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.