Do you find this script useful?
Yes
No
Comments?
Sort buttons
This script supports the addition of script buttons to a report form that will, when pressed, sort the report by a specified field. The script buttons may appear as column heads, and should be report headers. The sample script contains 3 such buttons, to sort by subject, title, and author, respectively.
Script Language: JavaScript For use with:
DB/TextWorks
DB/SearchWorks
DB/Text Run-time
Requires at least version 4.1
// Add three script buttons to your form. Change the buttons
// to header boxes so that they appear only at the beginning
// of the report. Give them script names "subject", "title",
// and "author", respectively.

function subject_onClick()
{
  var crs = Application.activeTextbase.currentRecordset;
  var sd = crs.newSortDescriptor();

  sd.sortFieldName(0) = "Subject";
  crs.Sort(sd);
  Command.refreshWindow();
}

function title_onClick()
{
  var crs = Application.activeTextbase.currentRecordset;
  var sd = crs.newSortDescriptor();

  sd.sortFieldName(0) = "Title";
  crs.Sort(sd);
  Command.refreshWindow();
}

function author_onClick()
{
  var crs = Application.activeTextbase.currentRecordset;
  var sd = crs.newSortDescriptor();

  sd.sortFieldName(0) = "Author";

  // If you don't want to explode the author field,
  // delete the following line.

  sd.sortFieldFlags(0) = sd.FieldFlagEXPLODE;
  crs.Sort(sd);
  Command.refreshWindow();
}
Notes: To generalize this script to use with other fields, change the field names assigned to the sortFieldName properties AND change the function names to match the script names given to the buttons.
Submitted by Inmagic Staff on 11/30/2000

Powered by DB/Text WebPublisher, from Inmagic WebPublisher PRO