# Recommendation for custom sorting of dropdown list dataset?

**URL:** <https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574>\
**Category:** Ignition\
**Tags:** vision, perspective\
**Created:** [December 13, 2022, 7:08pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574 "2022-12-13T19:08:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpavlicek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rpavlicek/32/55868_2.png) [@rpavlicek](https://forum.inductiveautomation.com/u/rpavlicek)\
**Post date:** [December 13, 2022, 7:08pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/1 "2022-12-13T19:08:05Z")

</div>

I've been wanting to implement a way to custom sort for different users of our location sites which are in dropdown list to navigate from. The reason, is everyday they go to each one in order how they go to each location. Right now, they are alphabetical (which is great for everyone else).

I can think of several ways to accomplish this, but seems rough or too hardcoded. However, I do expect some hardcoding and maintenance.

1. For instance, I can add a new sql column of integer in the main table, put in 1-xx and when I run the query, I can do an "order by" on that new integer column. However, I need it a little more dynamic for 2+ users.

2. Another way is to create another table relationship off our main once specifically for this which would separate it from the main table so it's not so cluttered. This new table would also have a column of user, so it can associate by that user for their sort order, but I see a lot of redundant location values, but maybe this is expected and best?

3. This could be done in a sql case statement (in the order by clause), aliasing a column to sort, but I don't think I can make this dynamic easily, even worse for maintenance compared to the above.

4. Then I could always sort within the binding by using python scripting, but need this to work smoothly in both Vision and Perspective.

I just need a recommendation on which practice might be best.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [December 13, 2022, 8:02pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/2 "2022-12-13T20:02:48Z")

</div>

I would create a separate table and save the locations in the order that each user wants. when you pull up the drop down list first check if there is an entry for that user in the "user ordered" table, if so load from that table, if not load in alphabetical order from the original table. You can probably have it automatically load into a client dataset tag when the user logs in so that there is no wait when the window is opened and bind the dropwdown to the client dataset tag in vision. not sure how that would work with perspective but I am sure there is a similar flow.

---

<div class="post-metadata">

**Author:** ![rpavlicek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rpavlicek/32/55868_2.png) [@rpavlicek](https://forum.inductiveautomation.com/u/rpavlicek)\
**Post date:** [December 13, 2022, 9:33pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/3 "2022-12-13T21:33:12Z")

</div>

Which format would be best, I'm leaning towards the tall (first) below?

Tall format, don't have to worry about adding columns, more dynamic.

| Location | User | Order |
| --- | --- | --- |
| Alpha | Tom | 4 |
| Beta | Tom | 3 |
| Charlie | Tom | 1 |
| Delta | Tom | 2 |
| Alpha | Amy | 3 |
| Beta | Amy | 1 |
| Charlie | Amy | 2 |
| Delta | Amy | 4 |

The format below, wider, saves space, but columns are not dynamic.

| Location | UserOrder1 | UserOrder2 |
| --- | --- | --- |
| Alpha | 4 | 3 |
| Beta | 3 | 1 |
| Charlie | 1 | 2 |
| Delta | 2 | 4 |

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [December 13, 2022, 9:41pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/4 "2022-12-13T21:41:31Z")

</div>

> [@rpavlicek](#):
>
> Tall format, don't have to worry about adding columns, more dynamic.

How would you handle adding rows if that requirement came up?

---

<div class="post-metadata">

**Author:** ![rpavlicek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rpavlicek/32/55868_2.png) [@rpavlicek](https://forum.inductiveautomation.com/u/rpavlicek)\
**Post date:** [December 13, 2022, 10:26pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/5 "2022-12-13T22:26:59Z")

</div>

I would setup the three columns as a unique index and with logic see if it exists or not.

Now that I think of it, I may try the wide format setup with a finite amount of user columns. I could add for instance 20 or more of these.

We have 300 locations, so 300 rows with 25 columns may be better than 6000 rows with several columns.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [December 13, 2022, 10:52pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/6 "2022-12-13T22:52:00Z")

</div>

Not every user needs a reference. If there isn't a user reference use the default.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [December 13, 2022, 11:57pm UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/7 "2022-12-13T23:57:36Z")

</div>

I would go with tall. I see no reason to go with a wide format although I am no database expert. Only thing I may add is a "group" id. while you may have only one group now in the future you may need the ability to sort on multiple groups where the same user has multiple groups assigned to them. you could always change later but if you add a group id column now you dont have to worry about that in the future.

6000 rows is nothing for a database table. I think you will have a big complicated mess if you try and do this with a wide table. IMO of course. If you are worried about saving space which isnt a concern imo you could serialize the dataset and store everything in 1 row

> [@How to serialize a dataset?](https://forum.inductiveautomation.com/t/how-to-serialize-a-dataset/11567/3):
>
> Well, I had just figured out how to do it in pure Python by converting the dataset to a list of lists, using the python pickle module to serialize it, base64 encoding it and putting it in the database… but thanks to pturmel I was able to get the Java version working in just a couple minutes. I also referred to this blog post: [joeygibson.com/2003/05/22/jytho … oo-useful/](https://joeygibson.com/2003/05/22/jython-is-just-too-useful/) . So here’s how I got it to work. Database (PSQL) has some character varying fields for identifying the save, and a bytea fiel…

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 14, 2022, 12:41am UTC](https://forum.inductiveautomation.com/t/recommendation-for-custom-sorting-of-dropdown-list-dataset/67574/8 "2022-12-14T00:41:19Z")

</div>

I would also recommend the tall format. Much cleaner and easier to maintain. If you remove a user from a parent user table, you can have a Foreign Key that automatically deletes the rows from this table, keeps the User values in sync in case you ever change a username, etc.

As @diat150 mentioned, 6,000 rows isn't even a shadow of a blip on the radar for databases.

For the `User` column, will that be a username/user id? They look like first names but I'm assuming you made up those examples. I just want to make sure you are using something that will always be unique to the user for this column.

Nice thing with this approach is you could pretty easily build a feature in the HMI that allows the user to reorganize the locations however they prefer and save them to this table. That could remove a lot of your maintenance headache concerns.
