1

Can someone please help me with search bar for Kendo UI Panelbar.

  1. When search I want it display on type='program'. Example if I search account the programs that have account words should appear.
  2. Currently it not working at all. It just expand all my panelbar program. :(

Here i provide dojo demo

My javascript

function myFunction() {

var panelbar = $("#panelbar").data("kendoPanelBar");
panelbar.expand($("li", panelbar.element));
//panelbar.collapse($("li", panelbar.element));

var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("panelbar");
li = ul.getElementsByTagName("li");

for (i = 0; i < li.length; i++) {
    a = li[i].getElementsByTagName("li")[0];
    txtValue = a.textContent || a.innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      li[i].style.display = "";
    } else {
      li[i].style.display = "none";
    }     
}
}

basically my nested list looks like this

<ul id="panelbar">
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search..."> 
<li type="module">Agencies &amp; Groups
    <ul>
    <li type="category">Agency &amp; Booker
    <ul>
    <li type="program">Agency &amp; Booker</li>
    <li type="program">Region</li>
    <li type="program">Sub Region</li>
    </ul>
    </li>
    <li type="program">Agency Category</li>
    <li type="program">Agency Contract</li>
    <li type="program">Agency Overview</li>
    </ul>
</li>   
<li type="module">Call Charge &amp; Billing
    <ul>
    <li type="category">JDS
    <ul>
    <li type="program">JDS Room Mapping</li>
    <li type="program">JDS Room Status</li>
    <li type="program">DS Interface</li>
    </ul>
    </li>
    <li type="category">Operator Panel
    <ul>
    <li type="program">Wake Up Call</li>
    <li type="program">Operator Panel</li>
    </ul>
    </li>       
    <li type="program">Call Code</li>
    <li type="program">Charge Rate</li>
    <li type="program">Property PABX</li>
    <li type="program">Call Transaction</li>
    </ul>
</li>

Here i provide dojo demo

Nixoderm
  • 355
  • 4
  • 23

1 Answers1

3

Type <LI> type attribute is for bullet types. Place your types values (i.e. hierarchy level categorization values) in the class attribute. Change

<li type="category" label=""><span class="k-icon ehors-subfolder-icon"></span>Account's Ledger … 

to

<li class="category" label=""><span class="k-icon ehors-subfolder-icon"></span>Account's Ledger ….

An id value should be unique among all the DOM elements (except maybe radio buttons). The leafs all have spans with the same id value, id="spanpanelbar". Place those in a class attribute as well. Change

<li type="program"><span id="spanpanelbar" class="k-icon ehors-folderopen-icon"></span>General Ledger</li>

to

<li class="program"><span class="spanpanelbar k-icon ehors-folderopen-icon"></span>General Ledger</li>

The search match result processing is changing only the style display property of the leafs. Change the processing to add a class to the <li>, corresponding to the search result condition.

style
.program.nomatch {display:block; color: lightgray } /* or simply display: none */
.program.match   {display:block;  }

javascript
match = $(this).text().match(searchRegEx);
$li = $(this);
$li.toggleClass("match", (match!=null)).toggleClass("nomatch",(match==null));

See this dojo, an update of your original one. It has bonus code for:

  • waiting for typing to stop
  • highlighting the matched fragment

enter image description here

The PanelBar widget is a hierarchical viewer. The items in the path to a program must be displayed in order to see the program. In order to display only paths to found programs you would:

  • At search start set all items to have nomatch class (hide everything)
  • When a match is made, set the program and it's parent items to have match class (unhide path to program)

Example:

    // hide top and middle tier so they wont show if there are no
    // subordinate programs that match

    $("li.category").toggleClass("nomatch", true).toggleClass("match",false);
    $("li.module")  .toggleClass("nomatch", true).toggleClass("match",false);

    // evaluate each program for matching the search term

    $("#panelbar li.program").each(function() { 
      var match, $li, $span, textnode, element;

      match = $(this).text().match(searchRegEx);
      $li = $(this);

      // hide/display programs according to match result

      $li.toggleClass("match", (match!=null))
         .toggleClass("nomatch",(match==null));

      // display items in path when match made

      if (match!=null) {
        $li.parentsUntil("#panelbar", "li")
          .toggleClass("match",true)
          .toggleClass("nomatch",false);
      }

dojo

Richard
  • 25,390
  • 3
  • 25
  • 38
  • Thank you for your response, Yes, it works like I want when search, but how to do it only display a **program** only. For example, when search word **mana**, result will display _Ledger Management_ & _Group Management_ only, So it not expand unnecessary thing. Its possible to do? Please help. – Nixoderm Mar 04 '19 at 02:22
  • You can collapse all and expand up through a matching li.program's .parentsUntil(), expanding the tiers that lead to it. Or similarly with match/nomatch class toggling on an expanded panelbar (Dojo updated). – Richard Mar 04 '19 at 03:03
  • Thanks again Richard! It has been an hour I try to edit your dojo sample, but not working. After search a program, how to display back kendo Panelbar back to normal, Example after search, then I clicked on backspace I want to display back all the programs.. Thanks again, you help me a lot. – Nixoderm Mar 04 '19 at 04:04
  • Either 1. add a reset button - click handler toggles all the match and nomatch classes off, 2. look at code closely, remove `if (filter.length < 3) return; // only search 3 or more characters in searchTerm` line use to prevent searching on very little,( or do the reset when searchTerm length is 0. ) – Richard Mar 04 '19 at 07:08
  • sorry my bad not display all the program, but it collapse all the panelbar. `panelbar.collapse($("li", panelbar.element));` if I clicked on backspace. – Nixoderm Mar 04 '19 at 07:30
  • Thank you for you help! – Nixoderm Mar 04 '19 at 09:01
  • @Nixoderm be sure to follow up with more than a comment. When you get see an acceptable answer you can mark it and up vote it. See SO topic [What should I do when someone answers my question](https://stackoverflow.com/help/someone-answers) – Richard Mar 04 '19 at 10:37