Sort items inside a listbox

Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

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?

 

Capture_019.png

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

390

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

Sort the items before you add it to the listbox.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

Thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 16, 2019 Nov 16, 2019

Copy link to clipboard

Copied

LATEST

Thank you Thom!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines