DropdownList Favourites

Hello,

We are using your DropdownList to show Countries in our UI.

But we would like to have all our neighbour countries as favourites in the first few places.

How can we achieve this without using Grouping?


Thanks for your help.

Regards Dominic


10 Replies

BC Berly Christopher Syncfusion Team August 4, 2021 02:22 PM UTC

Hi Chris,  
  
Greetings from Syncfusion support. 
  
We have checked the requested requirement. If you want to display the result based on the favorite item without grouping feature, we can sort the data source based on favorite item and assign it to the component as mentioned below, 
  
Here, we have sorted the data source based on the field value named as “Favorite” and assign it to the DropDownList component. 
  
  public class Vegetables 
    { 
        public string Vegetable { get; set; } 
        public string Category { get; set; } 
        public string Id { get; set; } 
        public bool Favorite { get; set; } 
        public List<Vegetables> VegetablesList() 
        { 
            List<Vegetables> veg = new List<Vegetables>(); 
            veg.Add(new Vegetables { Vegetable = "Cabbage Leafy and Salad", Category = "Leafy and Salad", Favorite = false }); 
            veg.Add(new Vegetables { Vegetable = "Chickpea", Category = "Beans", Favorite = false }); 
            veg.Add(new Vegetables { Vegetable = "Garlic", Category = "Bulb and Stem", Favorite=true }); 
            veg.Add(new Vegetables { Vegetable = "Green bean", Category = "Beans", Favorite = false }); 
            veg.Add(new Vegetables { Vegetable = "Horse gram", Category = "Beans", Favorite=true }); 
            veg.Add(new Vegetables { Vegetable = "Nopal", Category = "Bulb and Stem", Favorite=false }); 
            veg.Add(new Vegetables { Vegetable = "Onion", Category = "Bulb and Stem", Favorite = false }); 
            veg.Add(new Vegetables { Vegetable = "Pumpkins", Category = "Leafy and Salad", Favorite = false }); 
            veg.Add(new Vegetables { Vegetable = "Spinach", Category = "Leafy and Salad", Favorite = true }); 
            return veg.OrderByDescending(o => o.Favorite).ToList(); 
        } 
    } 
  public IActionResult Index() 
        { 
            ViewBag.data = new Vegetables().VegetablesList(); 
 
            return View(); 
        } 
      
 
  
For your convenience, we have prepared the sample and attached it below, 
  
Regards, 
Berly B.C 



CH Chris August 5, 2021 05:33 AM UTC

Thank you very much!

This is totally what I was looking for :-)

Where do you have documented all those Special Attributes we can use in Syncfusion, as I am not able to find them in the documentation.


Regards Dominic



BC Berly Christopher Syncfusion Team August 5, 2021 11:16 AM UTC

Hi Chris, 
  
We have sorted the data in the list which is assigned before it to the DropDownList component with help of C# standard methods. You can find these details from the below MSDN documentation. 
  
  
Regards, 
Berly B.C 



CH Chris August 16, 2021 09:02 AM UTC

I have an additional question.


How can I achieve this in the Grid Edit Modal?

I pass that information to the Grid:


But then in the Grid Edit Modal, I can only see this:


 So this list is not sorted or anything.



CH Chris replied to Christoph Zürcher November 26, 2021 10:00 AM UTC

Is there any possibility to achieve this?



BC Berly Christopher Syncfusion Team November 29, 2021 11:42 AM UTC

Hi Christoph,  
  
Before proceeding the request, please share the below details that will help us to check and proceed further from our end.  
  
  • Is your requirement to change the sort order of the data in the edit dropdown list?
  • Or else are you reporting problem that the foreign key data is not properly displayed in the Grid edit dropdown? If this is your case, then please share us the entire column code for this foreign key column.
  • Share us a video demonstration of the case for better understanding.
  
If your requirement does not come under the above cases or if you wish to share us any additional information regarding your requirement, then please share us the same.  
  
Regards,  
Berly B.C 



CH Chris December 1, 2021 09:04 AM UTC

Hello Berly,


Is your requirement to change the sort order of the data in the edit dropdown list?

-> This is exactly what we want.


We were able to sort the Dropdown values in a normal dropdown.

But this is not applied in the Grid Edit Modal (DropDownEdit).


So there has to be a possibility to achieve this in some way. But I can't find out how to.



RR Rajapandi Ravi Syncfusion Team December 2, 2021 12:58 PM UTC

Hi Christoph, 

Thanks for the update 

By default, in our EJ2 Grid, the dropdown list datasource was sorted in ascending order. Please refer the below screenshot for more information. 

Screenshot: 

 

Before we start providing solution on your query, we need some information for our clarification. Please share the below details that will be helpful for us to provide better solution. 

1)             Please share your exact requirement with detailed description. 

2)             Share us a video demonstration of the case for better understanding. 

3)             If possible, explain your requirement scenario with pictorial representation. 


Rajapandi R 




CH Chris December 13, 2021 07:10 AM UTC

My requirement:
I need an EJ-Grid Drop-Down edit, where I can set Switzerland and other Countries to the top of the list.
With this favorite prop, I could achieve this in the Grid Edit. I could do it only in a normal drop-down edit.


When I add those favorite tags:



And order them in the controller by Favorite, DisplayName then no sort will be visible in the EJ-Grid Drop-Down edit modal.



So my question is:
How can I sort them in the Grid Drop-Down edit?


Is there some JS code I have to run?

Or how can I change the sort order in the Grid Drop-Down?


I hope my needs are clear, if not please ask back.


Best Regards



RR Rajapandi Ravi Syncfusion Team December 14, 2021 12:51 PM UTC

Hi Chris, 

Thanks for the update 

From your update, we could see that you like to display the Foreign key column as ascending order in Grid initial rendering. Based on your query we would like to inform you that returning the foreign key datasource in ascending order cannot help to render the foreign key column in ascending order in Grid. Because the Grid foreign key column was rendered based on that mapping Field. So, in initial rendering the Grid foreign key column will render based on that mapping field order. It was the default behavior of Grid. 

Rajapandi R 


Loader.
Up arrow icon