Skip to main content
JR Boulay
Community Expert
Community Expert
Nov 14, 2019 2:17 PM UTC
Question

Sort items inside a listbox

I have some listboxes whose items are filled in by a script and/or via a CSV.


1. I would like items containing "T*T" to appear at the top of the list, sorted alphabetically. (As this word is censored by the forum I wrote it "T * T", you can see it on the screenshot)
2. I would like items containing "ADE" (and not containing "T*T") to appear next, sorted alphabetically.
3. And I would like all the other items to appear after, sorted alphabetically.

 

See screenshot: white list is the current, yellow list is what I want.

Is it possible?

 

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
Nov 14, 2019 3:13 PM UTC

Thank you.

Translate
Acrobate du PDF, InDesigner et Photoshopographe
Thom Parker
Community Expert
Community Expert
Nov 14, 2019 5:58 PM UTC

Hi JR, here's a 30sec script

 

var oFld = this.getField("List1");
var len = oFld.numItems;
var aItems = [];
for(var i=0;i<len;i++)
     aItems.push([oFld.getItemAt(i,false),oFld.getItemAt(i,true)]);
oFld.setItems(aItems.sort())

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
Nov 16, 2019 8:58 AM UTC

Thank you Thom!

Translate
Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
Nov 14, 2019 2:28 PM UTC

I cannot, items are sometimes added in several times by multiple scripts.

Translate
Acrobate du PDF, InDesigner et Photoshopographe
Bernd Alheit
Community Expert
Community Expert
Nov 14, 2019 2:31 PM UTC

Then get the items from the listbox, sort the items, and add the items to the listbox.

Translate
Bernd Alheit
Community Expert
Community Expert
Nov 14, 2019 2:24 PM UTC

Sort the items before you add it to the listbox.

Translate