[]
        
(Showing Draft Content)

SortFieldBase

Class SortFieldBase

java.lang.Object
com.grapecity.documents.excel.SortFieldBase
All Implemented Interfaces:
ISortField
Direct Known Subclasses:
CellColorSortField, FontColorSortField, IconSortField, ValueSortField

public abstract class SortFieldBase extends Object implements ISortField
Represents the abstract base class for sort fields.

This class provides the common implementation of ISortField for worksheet sorting. It encapsulates the shared sort metadata used by concrete sort field types, including the key range, the sort priority in a multi-key sort, and the criterion specified by ISortField.getSortOn().

Use one of its concrete subclasses when defining sort behavior for values, cell fill colors, font colors, or icons. Instances of this type are typically managed as part of a sort definition rather than instantiated directly.

  • Constructor Details

    • SortFieldBase

      public SortFieldBase()
  • Method Details

    • getKey

      public final IRange getKey()
      Gets the range used as the sort key.

      Returns the IRange assigned to this sort field. This range identifies the cells used to evaluate the sort order for the field.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Score"},
           {"Tom", 80},
           {"Ada", 95},
           {"Ken", 88}
       });
       ISortField sortField = new ValueSortField(worksheet.getRange("B2:B4"), SortOrder.Ascending);
       IRange key = sortField.getKey();
       
      Specified by:
      getKey in interface ISortField
      Returns:
      The range that serves as the sort key for this sort field.
    • getPriority

      public final int getPriority()
      Gets the priority of this sort field for multi-field sorting.

      Use this property to determine the order in which this sort field is applied when multiple sort fields are used together. To change the priority, use setPriority(int).

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Group", "Code", "Rank"},
           {2, "g", 30},
           {1, "z", 20},
           {1, "a", 10},
           {3, "b", 40}
       });
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:C5"));
       sort.getSortFields().add(new ValueSortField(worksheet.getRange("A2:A5"), SortOrder.Ascending));
       ValueSortField sortField = new ValueSortField(worksheet.getRange("B2:B5"), SortOrder.Descending);
       sort.getSortFields().add(sortField);
       sortField.setPriority(1);
       int priority = sortField.getPriority();
       
      Specified by:
      getPriority in interface ISortField
      Returns:
      The priority of this sort field for multi-field sorting.
    • setPriority

      public final void setPriority(int value)
      Sets the priority of this sort field for multi-field sorting.
      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Group", "Code", "Rank"},
           {2, "g", 30},
           {1, "z", 20},
           {1, "a", 10},
           {3, "b", 40}
       });
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:C5"));
       sort.getSortFields().add(new ValueSortField(worksheet.getRange("A2:A5"), SortOrder.Ascending));
       ValueSortField sortField = new ValueSortField(worksheet.getRange("B2:B5"), SortOrder.Descending);
       sort.getSortFields().add(sortField);
       sortField.setPriority(1);
       
      Specified by:
      setPriority in interface ISortField
      Parameters:
      value - The priority of this sort field for multi-field sorting.
    • getSortOn

      public final SortOnType getSortOn()
      Gets the criterion used by this sort field.

      The returned value depends on the concrete sort-field type. A ValueSortField returns SortOnType.Values, a CellColorSortField returns SortOnType.CellColor, a FontColorSortField returns SortOnType.FontColor, and an IconSortField returns SortOnType.CellIcon.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {
           {3}, {1}, {2}
       });
       SortFieldBase sortField = new ValueSortField(worksheet.getRange("A1:A3"), SortOrder.Ascending);
       SortOnType sortOn = sortField.getSortOn();
       
      Specified by:
      getSortOn in interface ISortField
      Returns:
      The SortOnType that specifies whether this sort field sorts on values, cell color, font color, or icon.