?
Solved

Filter tree control by typing in a textbox using Jquery

Posted on 2013-02-07
6
Medium Priority
?
767 Views
Last Modified: 2013-02-08
I have a textbox and a tree control on a page that I need to filter the contents of the tree as I type in the textbox. My tree control has 2 levels to it. The root level is alpha type characters and the child level is numeric based on the following...
<ul class="BNG">
     <li class="BNH">Aiken
          <ul class="BNG">
               <li class="BNH">1550
               <li class="BNH">7456
               <li class="BNH">4589
          </ul>
     </li>
</ul>

This is a short grouping. The tree has many parent and child nodes. It is possible that there might be a numeric character in the root node and also possible to have a alpha character in the child node. I need to have a Jquery code filter the child and root nodes as I type in the textbox. I have been trying to use the .keyup function of the textbox for this. If I type "15" in the textbox I need the root node Aiken to be visible and the child node 1550 to be visible. If I type "Aik" in the textbox, I need the root node Aiken to be visible as well as all the child nodes for Aiken (1550, 7456, 4589). My java and jquery is beginner level and would appreciate any help on this. Thanks!
0
Comment
Question by:Cubbybulin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38867503
Test page : http://jsfiddle.net/xwkQ5/
$(document).ready(function() {
    $("#textbox").bind("keyup change blur paste", function() {
        var term = $(this).val();
        $("ul,li", ".BNG").filter(function() { return $(this).text().indexOf(term)>=0; }).show()
        $("ul,li", ".BNG").filter(function() { return $(this).text().indexOf(term)<0; }).hide()
    })
})

Open in new window

0
 

Author Comment

by:Cubbybulin
ID: 38867577
Thank you for your reply! I tested this and it partially works. When I type "15" in the text box it does show the Aiken root node and the 1550 child node. Which is perfect. However, when I type "Aik" it only shows the Aiken root node and not all of the child nodes associated with Aiken. Is this doable?
One other thing is that it is case sensitive. If I type "a", Aiken does not show up unless I type "A". Is this doable not to have it case sensitive?

Thanks!
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 38867636
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:Cubbybulin
ID: 38868300
This works great, except it is very, very slow in executing. Any ideas on how to speed it up or is just a factor of page contenet?
There are allot of other controls on my page.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38868320
not really
maybe use the server with or without ajax to do the filtering
0
 

Author Comment

by:Cubbybulin
ID: 38868373
ok, thanks for your help! code is exactly what I was after!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question