Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Filter tree control by typing in a textbox using Jquery

Posted on 2013-02-07
6
Medium Priority
?
770 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

618 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