PDA

View Full Version : [FIXED] StoreFilterField bug



ocooper
9 Jul 2009, 1:51 AM
Hi,

In the following example there are two issues. If the clear filter X button is clicked, only the first 3 nodes of the tree are then displayed (see screenshots). This can be fixed by overriding the on TriggerClick method and explicitly calling the layout() method of the tree's parent ContentPanel (see commented out section of code) but I shouldn't have to do this?

Also, if the items being filtered are root nodes (i.e. type 'Node' into the filter field) then only the first 3 matches are displayed even though all are being selected by the doSelect() method.

Original (unfiltered) tree:
http://oasp-beta.athensams.net/oalahelp/OALAHelp/original.png

Filtered on name of root nodes (BUG?):
http://oasp-beta.athensams.net/oalahelp/OALAHelp/node-filtered.png

Once the clear filter 'x' button has been clicked (BUG?):
http://oasp-beta.athensams.net/oalahelp/OALAHelp/cleared.png

Filter on name of leaf/sub nodes (displays OK):
http://oasp-beta.athensams.net/oalahelp/OALAHelp/sub-filtered.png

Here is the example code:



package uk.org.eduserv.GXTTreePanelBugTest.client;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.layout.FlowData;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/

public class GXTTreeTest implements EntryPoint
{
TreeStore<BaseTreeModel> store = new TreeStore<BaseTreeModel>();

public void onModuleLoad()
{
TreePanel<BaseTreeModel> tree = createTree();
final ContentPanel cp = new ContentPanel();

StoreFilterField<BaseTreeModel> filter = new StoreFilterField<BaseTreeModel>() {

@Override
protected boolean doSelect(Store<BaseTreeModel> store, BaseTreeModel parent, BaseTreeModel record, String property, String filter)
{
String name = record.get("displayName");
if(name.trim().toLowerCase().startsWith(filter.toLowerCase())) {
return true;
}

return false;
}

// @Override
// protected void onTriggerClick(ComponentEvent ce) {
// super.onTriggerClick(ce);
// setValue(null);
// onFilter();
// cp.layout();
// }
};

filter.bind(store);
filter.setToolTip("Search help");
filter.setEmptyText("Search");

ToolBar tb = new ToolBar();
tb.setBorders(true);

tb.add(filter);

cp.setHeaderVisible(false);
cp.setTopComponent(tb);
cp.add(tree, new FlowData(10));
cp.setScrollMode(Scroll.AUTO);
cp.layout();

RootPanel.get().add(cp);
}

private TreePanel<BaseTreeModel> createTree()
{
BaseTreeModel[] m = new BaseTreeModel[7];

for(int i = 0; i < m.length; i++) {
m[i] = new BaseTreeModel();
m[i].set("displayName", "Node " + (i+1));
BaseTreeModel sub = new BaseTreeModel();
sub.set("displayName", "Sub-Node");
m[i].add(sub);
store.add(m[i], true);
}

TreePanel<BaseTreeModel> retTree = new TreePanel<BaseTreeModel>(store);
retTree.setDisplayProperty("displayName");

Info.display("Tree Nodes", "No of root nodes that SHOULD be displaying: "
+ store.getRootItems().size());

return retTree;
}
}



Many Thanks,

Oli Cooper.

sven
10 Jul 2009, 7:48 AM
Fixed in SVN.