Skip to main content
Participant
January 26, 2025
Question

Adobe Live Cycle Date Time based table rows sorting

  • January 26, 2025
  • 0 replies
  • 132 views

Helle gurus,

Can you please provide a redirect for the javascript codes required to sort the rows of the table below in descending order according to the date and start time, that is, from old to new?

I wrote the code but it was not successful. First table is binding one. Second one can be used for sorting one or first one. 

var tableRows = xfa.resolveNodes(“FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries1.Row1[*]”);

// Convert rows to an array for sorting
var rowsArray = [];
for (var i = 0; i < tableRows.length; i++) {
rowsArray.push(tableRows.item(i));
}

// Sort array by colDate
rowsArray.sort(function (a, b) {
var dateA = new Date(a.colDate.rawValue); // Parsing colDate as a date
var dateB = new Date(b.colDate.rawValue);

// Compare dates (ascending order)
if (dateA < dateB) return -1;
if (dateA > dateB) return 1;
returns 0;
});

// Reorder the table by sorted rows
for (var j = 0; j < rowsArray.length; j++) {
// Copy sorted row values back to table rows
var sortedRow = rowsArray[j];

FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colDate.rawValue = sortedRow.colDate.rawValue;
FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colTimeType.rawValue = sortedRow.colTimeType.rawValue;
FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colStartTime.rawValue = sortedRow.colStartTime.rawValue;
FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colEndTime.rawValue = sortedRow.colEndTime.rawValue;
FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colDuration.rawValue = sortedRow.colDuration.rawValue;
FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colEmployee.rawValue = sortedRow.colEmployee.rawValue;
FormServiceRequestConfirmation.bdyMain1.frmTimeEntries.tblTimeEntries.Row1[j].colContract.rawValue = sortedRow.colContract.rawValue;
}

 

 

Thanks

John