Sorting Dropdown List

BitLost

Active member
Joined
Dec 10, 2016
Messages
35
Programming Experience
Beginner
I am fairly new to MVC and just feeling my way to a large extent. I am following along tutorials on ASP.Net and havent read a book yet, although I have got one on order.

I have created a rather large database and commenced to work on it in EF.

One of the tables I have prepopulated is some 10,000 records. I am not used to working in MVC yet, so maybe this question is simple in its naivety.

I would like to alphabetically sort the 10,000 records. I am not sure which way to approach this? Should I sort at the server? Should I sort only in the view? Should I not sort and somehow call back to the server to return a limited set as the user types? Which is most efficient?

Is there any advantage to partially filtering by perhaps creating a sql statement that returns the most common records first?

And so on?
 
You absolutely should not load 10k records into a drop-down list. That's just too many and will adversely affect both server and client performance.

Most of the projects I work on are C# and MVC and we use a jQuery plugin to provide an auto-completed suggestion list in such scenarios. I'm not sure exactly which one it is but we found it just by searching the web so you can do the same. I'm back in the office tomorrow after our Christmas break so I can tell you then if you want.

This plugin allows you to call an action when the text in a text box changes. We generally specify that at least two characters must be typed and the query that gets executed by the action returns the first five records that contain the specified value as sorted alphabetically. It's up to you what criteria you use though. You will be the one writing the query so you can match on the start of the text or any part of the text and you can sort by any criteria you want, e.g. creation date. You can also return as many matches as you want but I would suggest that any more than ten will get a bit unwieldy.
 
Most of the projects I work on are C# and MVC and we use a jQuery plugin to provide an auto-completed suggestion list in such scenarios. I'm not sure exactly which one it is but we found it just by searching the web so you can do the same. I'm back in the office tomorrow after our Christmas break so I can tell you then if you want.

I'd appreciate that. As I said I am very new to this, so more help is better at the moment.
 
However, as a learner I also want to re-order other drop down lists. I was hoping to cover all with one answer?
 
However, as a learner I also want to re-order other drop down lists. I was hoping to cover all with one answer?
As you're using EF, you do the sorting in the query. Just as you filter the data with a Where call, you sort the data with an OrderBy call. That is regardless of what you're going to do with the data. It applies to data that you're going to load into a drop-down list, an auto-complete list or somewhere else.
 
Back
Top Bottom