I have googled and searched the forms for days for an answer, but have been unsucessful.
Since the only thread I found is a year old, I wanted to start a new one instead of bumping the old one
Ref : http://forums.adobe.com/message/3000436
I am looking for a script to sort the data in a form based on user input.
The form is just a table with multiple rows and 3-5 colums (depending on the dept it is used by)
Using the above referenced thread, I was able to get static table to sort, but i need to have all fields be text fields and the users inputs the data.
The example from the other thread of the static:
![http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-3000436-35301/364-128/Untitled.png]()
I will use the same layout, just need it to be a form instead of static.
If anyone can help, or point me in the right direction, that would be great.
Update #1:
I did locate this page:http://cookbooks.adobe.com/post_Sorting_tables_in_dynamic_PDF-18993.html
I got the sort to work and it appears to be mostly what I am looking for, but how do i deal with blank field??
Example, the last three rows are blank ( no data) the sort fails.
Here is the code from the page, how can i modify it to correct for the blank fields?
------------------------------------------------
var col = 0; // column index
var num = false; // Is numeric column
var OrderAsc = true; // Order of sorting
function SortTable(tableRef,colIndex,isNumeric,Asc)
{
try
{
col = colIndex;
num = isNumeric;
OrderAsc = Asc;
// String variable containing the form data as XML String
var data = tableRef.saveXML('pretty');
// An XML variable contains the deserialized XML data
var xmlData = xfa.datasets.createNode("dataGroup",tableRef.name);
xmlData.loadXML(data);
// Number of table rows
var rowsCount = xmlData.nodes.length;
//Number of columns in the table
var cols = xmlData.nodes.item(1).nodes.length;
// A two dimensional array contains complete table data
var master = new Array();
// Fill the array with XML data
for(var i=1;i<rowsCount;i++)
{
master[i-1] = new Array();
for(var j=0;j<cols;j++)
{
master[i-1][j] = xmlData.nodes.item(i).nodes.item(j).value;
}
}
//Sort the 2D array
master.sort(sortFunc);
// Re-fill the XML variable with Array data
for(var i=0;i<master.length;i++)
{
for(var j=0;j<master[i].length;j++)
{
xmlData.nodes.item(i+1).nodes.item(j).value = master[i][j];
}
}
// Modify the table data and remerge the form
var result = xmlData.saveXML('pretty');
tableRef.loadXML(result,1,1);
xfa.form.remerge();
}catch(e)
{
app.alert(e)
}
}
// Customize the sort function to handle 2D array and Numeric columns
function sortFunc(a,b)
{
var x = a[col];
var y = b[col];
try
{
if(num)
{
x = parseInt(a[col]);
y = parseInt(b[col]);
}
}catch(e){}
if(OrderAsc)
{
return x==y?0: (x < y ? -1 :1)
}
else
{
return x==y?0: (x < y ? 1 :-1)
}
}