Solved

Filter tree control by typing in a textbox using Jquery

Posted on 2013-02-07
6
744 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 500 total points
ID: 38867636
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

738 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