I want to resize dropdown after set its dataSource

3 Answers 688 Views
DropDownList
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
FranckSix asked on 04 May 2023, 01:11 PM

Hi,

I build a Kendo Dojo to demonstrate my point :

Dojo

I want to adjust the size of my DropDownList after each setDataSource command.

The current behavior adjust the height on first setDataSource only. I place two buttons to expose my point. If i click Small and Large after, the dropdown is very small and I need to scroll. Otherwise if I click the large button and small after, the dropdown is very large and show empty spaces after items.

I try resise, and refresh but it not working.

How can I adjust the size manually ? Thanks!

FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 04 May 2023, 03:12 PM

It's seems that the popup container set it's size at first opened and never change after

3 Answers, 1 is accepted

Sort by
1
Accepted
Neli
Telerik team
answered on 09 May 2023, 06:13 AM

Hi Francis,

I would suggest handling the open event of the component. In the event handler, you can check the count of the items in the dataSource and based on that you can change the styles of the popup.

 open: function(){
        
        setTimeout(function(){
            var items = dropdownlist.dataSource.data().length * 28
            $(".k-list-content, .k-list, .k-popup").height(items);  
          })
      }

Here you will find the modified Dojo example.

I hope this helps.

Regards,
Neli
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 09 May 2023, 12:06 PM

Cool nice workaround, apart from a slight flicker when opening, it works!

Thank you

0
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 09 May 2023, 06:49 PM | edited on 09 May 2023, 06:58 PM

Hi @Neli,

Another little thing, If I have many DropDownList on same page the solution adapt all dropdown to same Height.
I try to pass sender over the open method but I cant reach the popup element. It seem to be on a div not under the sender.

There is a way to retreive the right popup to apply your solution ?

This is my latests attempt, 
I keep trying :

    $("#dropdownlist").kendoDropDownList({
      autoWidth: true,
      dataTextField: "text",
      dataValueField: "value",
      open: function(e){
        setTimeout(function(){
            var items = e.sender.dataSource.data().length * 28;
          	$("#" + e.sender.element.attr("id") + "-list").closest(".k-list-content, .k-list, .k-popup").height(items);
          })
      }
    }); 
Thanks!
0
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 09 May 2023, 07:06 PM
I found a workaround not the easy way... but it work!
    $("#dropdownlist").kendoDropDownList({
      autoWidth: true,
      dataTextField: "text",
      dataValueField: "value",
      open: function(e){
        setTimeout(function(){
          var liste = $("#" + e.sender.element.attr("id") + "-list");
          var content = liste.find(".k-list-content");
          var popup = liste.closest(".k-popup");
          
          var items = e.sender.dataSource.data().length * 28;
          liste.height(items);
          content.height(items);
          popup.height(items);
        })
      }
    });  
Neli
Telerik team
commented on 12 May 2023, 07:21 AM

Hi Francis,

I am glad to hear that you have managed to find a workaround for the issue and thank you very much for sharing with the community. I am sure it will be helpful to the other users that have the same scenario.

Regards,

Neli

Tags
DropDownList
Asked by
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Neli
Telerik team
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or