Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. searchable dropdown with large dataset

searchable dropdown with large dataset

Scheduled Pinned Locked Moved Web Development
javascriptdata-structurestools
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    I have a data of more that 500000 records which want to search data and fill in dropdown list. I am using dropdown list its working buts it is very slow

    <script type = "text/javascript">

        var ddlText, ddlValue, ddl, lblMesg;
    
        function CacheItems() {
    
            ddlText = new Array();
    
            ddlValue = new Array();
    
            ddl = document.getElementById("<%=ddlItems.ClientID %>");
    
            lblMesg = document.getElementById("<%=lblMessage.ClientID%>");
    
            for (var i = 0; i < ddl.options.length; i++) {
    
                ddlText\[ddlText.length\] = ddl.options\[i\].text;
    
                ddlValue\[ddlValue.length\] = ddl.options\[i\].value;
    
            }
    
        }
    
        window.onload = CacheItems;
    
    
    
        function FilterItems(value) {
    
            ddl.options.length = 0;
    
            for (var i = 0; i < ddlText.length; i++) {
    
                if (ddlText\[i\].toLowerCase().indexOf(value) != -1) {
    
                    AddItem(ddlText\[i\], ddlValue\[i\]);
    
                }
    
            }
    
            lblMesg.innerHTML = ddl.options.length + " items found.";
    
            if (ddl.options.length == 0) {
    
                AddItem("No items found.", "");
    
            }
    
        }
    
    
    
        function AddItem(text, value) {
    
            var opt = document.createElement("option");
    
            opt.text = text;
    
            opt.value = value;
    
            ddl.options.add(opt);
    
        }
    

    </script>

    F 1 Reply Last reply
    0
    • B byka

      I have a data of more that 500000 records which want to search data and fill in dropdown list. I am using dropdown list its working buts it is very slow

      <script type = "text/javascript">

          var ddlText, ddlValue, ddl, lblMesg;
      
          function CacheItems() {
      
              ddlText = new Array();
      
              ddlValue = new Array();
      
              ddl = document.getElementById("<%=ddlItems.ClientID %>");
      
              lblMesg = document.getElementById("<%=lblMessage.ClientID%>");
      
              for (var i = 0; i < ddl.options.length; i++) {
      
                  ddlText\[ddlText.length\] = ddl.options\[i\].text;
      
                  ddlValue\[ddlValue.length\] = ddl.options\[i\].value;
      
              }
      
          }
      
          window.onload = CacheItems;
      
      
      
          function FilterItems(value) {
      
              ddl.options.length = 0;
      
              for (var i = 0; i < ddlText.length; i++) {
      
                  if (ddlText\[i\].toLowerCase().indexOf(value) != -1) {
      
                      AddItem(ddlText\[i\], ddlValue\[i\]);
      
                  }
      
              }
      
              lblMesg.innerHTML = ddl.options.length + " items found.";
      
              if (ddl.options.length == 0) {
      
                  AddItem("No items found.", "");
      
              }
      
          }
      
      
      
          function AddItem(text, value) {
      
              var opt = document.createElement("option");
      
              opt.text = text;
      
              opt.value = value;
      
              ddl.options.add(opt);
      
          }
      

      </script>

      F Offline
      F Offline
      F ES Sitecore
      wrote on last edited by
      #2

      If you're showing 500000 items then a dropdown is the wrong thing to use. Use an autocomplete textbox instead. Google for how to write one.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups