Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Proxmox VE - Fix strange ID-based sorting to sort by VM/container names instead
--- /usr/share/pve-manager/js/pvemanagerlib.js 2021-11-24 11:32:51.000000000 -0600
+++ /usr/share/pve-manager/js/bc-pvemanagerlib.js 2021-11-29 15:44:54.070286236 -0600
@@ -3785,7 +3785,7 @@
if (Ext.isNumeric(info.vmid) && info.vmid > 0) {
text = String(info.vmid);
if ( {
- text += " (" + + ')';
+ text = + ' (' + text + ')';
} else { // node, pool, storage
text = info[info.type] ||;
@@ -12471,6 +12471,11 @@
if (!n1.template !== !n2.template) {
return n1.template ? 1 : -1; // sort templates after regular VMs
+ if ( > {
+ return 1;
+ } else if ( < {
+ return -1;
+ }
if (n1.vmid > n2.vmid) { // prefer VMID as metric for guests
return 1;
} else if (n1.vmid < n2.vmid) {

Proxmox Sorting

Proxmox VE does two very unusual things:

  • Places onto an admin the burden of manually managing numeric unique IDs for each VM/container.
  • Sorts VMs/containers in the UI by those IDs rather than their names, with no option to change the behavior. (While the table views in the right-hand detail pane does allow you to click around to sort by names and a few other things, it doesn't remember that, but the tree views in the left hand pane always sort by IDs regardless with no option to change).

The reasons for this aren't clear and aren't stated anywhere in the docs, nor any of the bug reports/feature requests related to this issue (some dating back on the order of a decade).

Why do I have to think about this at all?

As a newcomer to Proxmox, forcing me to worry about IDs adds this weird point of friction to creating and managing my VMs, and doesn't seem to offer me any benefit in return. I don't want to waste time agonizing over how I should structure and space out IDs just to get them sorted alphabetically, in their natural order. I know a lot of professional sysadmins but can't think of one who would naturally think about their VMs by numeric IDs instead of hostnames. Maybe they have to use a hypervisor's underlying auto-generated IDs occasionally to diagnose/fix specific issues or to run CLI commands, but IDs as the nominal case? No.

I know the system needs fixed IDs of some kind so that you can rename VMs and not screw everything up under the hood—that's normal, and much appreciated. Human-managed numeric identifiers is not a normal feature of a hypervisor nor a hypervisor management system.

The PVE manager's resource tree appears to sort by a few things, first by resource type for grouping of like things (VM, container, storage), then by their IDs. The label it shows in the UI for a given resource is a calculated field that it calls a description, which includes its ID, then its name (when applicable and available). That combined description is also displayed in detailed VM lists that the UI renders, and the JS-based ResourceStore code is the place where that gets generated.

This diff patches the latter half of the sorting behavior to sort by name instead, and changes the tree and table labels from "ID (name)" to "name (ID)".

It can be applied cleanly to pve-manager 7.1's copy of /usr/share/pve-manager/js/pvemanagerlib.js (both 7.1 and 7.0 patch cleanly), which appears to be combined at build time from multiple JS files, but ultimately the affected logic comes from www/manager6/data/ResourceStore.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment