Solved

Filter tree control by typing in a textbox using Jquery

Posted on 2013-02-07
6
710 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
  • 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 500 total points
ID: 38867636
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now