Skip to main content
JR Boulay
Community Expert
Community Expert
November 14, 2019
Question

Sort items inside a listbox

  • November 14, 2019
  • 3 replies
  • 1173 views

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 has been closed for replies.

3 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
November 14, 2019

Thank you.

Acrobate du PDF, InDesigner et Photoshopographe
Thom Parker
Community Expert
Community Expert
November 14, 2019

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())

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
November 16, 2019

Thank you Thom!

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
November 14, 2019

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

Acrobate du PDF, InDesigner et Photoshopographe
Bernd Alheit
Community Expert
Community Expert
November 14, 2019

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

Bernd Alheit
Community Expert
Community Expert
November 14, 2019

Sort the items before you add it to the listbox.