Asp.net mvc dropdownlist add items on scrolling

后端 未结 2 1061
独厮守ぢ
独厮守ぢ 2021-02-10 17:53

I am looking for asp.net mvc dropdown list which can adds records if scrollbar is scrolled. I am completely beginner to this area. Could some one guide me on how to implement th

相关标签:
2条回答
  • 2021-02-10 18:36

    Jquery Code

    Below is the Code for using ajax call to controller and get records then bind into to dropdown

    var mySelect = $('#mySelect');
     var sIndex = 11, offSet = 10, isPreviousEventComplete = true, isDataAvailable = true;
    
        mySelect.scroll(function (e) {
       if($(this).scrollTop() + $(this).innerHeight()>=$(this)[0].scrollHeight)
       {   
           var scrollto=$(this).scrollTop();
           if (isPreviousEventComplete && isDataAvailable) {       
              isPreviousEventComplete = false;
            $(".LoaderImage").css("display", "block");
    
            $.ajax({
              type: "GET",
              url: 'Your url',
              success: function (result) {
                       $.each(result, function(val, text) {            
        mySelect.append(
            $('<option></option>').val(val).html(text)
        );
            });
               mySelect.scrollTop( scrollto );
    
                isPreviousEventComplete = true;
    
                if (result == '') //When data is not available
                    isDataAvailable = false;
    
                $(".LoaderImage").css("display", "none");
              },
              error: function (error) {
                  alert(error);
              }
            });
    
    
          }
                   }
        });
    

    Click Demo Link http://jsfiddle.net/sethuramanP/4pmKf/3/ example for add static data to dropdown whenever scroll comes end

    0 讨论(0)
  • 2021-02-10 18:42

    You can also try this JQuery Select which will support infinite scroll of results.

    0 讨论(0)
提交回复
热议问题