def sort
        return unless @model
        return if @sort_keys.empty?
        $log.debug "TABULAR SORT KEYS #{sort_keys} "
        # first row is the header which should remain in place
        # We could have kept column headers separate, but then too much of mucking around
        # with textpad, this way we avoid touching it
        header = @model.delete_at 0
        begin
          # next line often can give error "array within array" - i think on date fields that
          #  contain nils
        @model.sort!{|x,y|
          res = 0
          @sort_keys.each { |ee|
            e = ee.abs-1 # since we had offsetted by 1 earlier
            abse = e.abs
            if ee < 0
              xx = x[abse]
              yy = y[abse]
              # the following checks are since nil values cause an error to be raised
              if xx.nil? && yy.nil?
                res = 0
              elsif xx.nil?
                res = 1
              elsif yy.nil?
                res = -1
              else
              res = y[abse] <=> x[abse]
              end
            else
              xx = x[e]
              yy = y[e]
              # the following checks are since nil values cause an error to be raised
              # whereas we want a nil to be wither treated as a zero or a blank
              if xx.nil? && yy.nil?
                res = 0
              elsif xx.nil?
                res = -1
              elsif yy.nil?
                res = 1
              else
              res = x[e] <=> y[e]
              end
            end
            break if res != 0
          }
          res
        }
        ensure
          @model.insert 0, header if header
        end
      end
def sort
        return unless @model
        return if @sort_keys.empty?
        $log.debug "TABULAR SORT KEYS #{sort_keys} "
        # first row is the header which should remain in place
        # We could have kept column headers separate, but then too much of mucking around
        # with textpad, this way we avoid touching it
        header = @model.delete_at 0
        begin
          # next line often can give error "array within array" - i think on date fields that
          #  contain nils
        @model.sort!{|x,y|
          res = 0
          @sort_keys.each { |ee|
            e = ee.abs-1 # since we had offsetted by 1 earlier
            abse = e.abs
            if ee < 0
              xx = x[abse]
              yy = y[abse]
              # the following checks are since nil values cause an error to be raised
              if xx.nil? && yy.nil?
                res = 0
              elsif xx.nil?
                res = 1
              elsif yy.nil?
                res = -1
              else
              res = y[abse] <=> x[abse]
              end
            else
              xx = x[e]
              yy = y[e]
              # the following checks are since nil values cause an error to be raised
              # whereas we want a nil to be wither treated as a zero or a blank
              if xx.nil? && yy.nil?
                res = 0
              elsif xx.nil?
                res = -1
              elsif yy.nil?
                res = 1
              else
              res = x[e] <=> y[e]
              end
            end
            break if res != 0
          }
          res
        }
        ensure
          @model.insert 0, header if header
        end
      end
def sort return unless @model return if @sort_keys . empty? $log . debug "TABULAR SORT KEYS #{sort_keys} " # first row is the header which should remain in place # We could have kept column headers separate, but then too much of mucking around # with textpad, this way we avoid touching it header = @model . delete_at 0 begin # next line often can give error "array within array" - i think on date fields that #  contain nils @model . sort! { | x , y | res = 0 @sort_keys . each { | ee | e = ee . abs - 1 # since we had offsetted by 1 earlier abse = e . abs if ee < 0 xx = x [ abse ] yy = y [ abse ] # the following checks are since nil values cause an error to be raised if xx . nil? && yy . nil? res = 0 elsif xx . nil? res = 1 elsif yy . nil? res = - 1 else res = y [ abse ] <=> x [ abse ] end else xx = x [ e ] yy = y [ e ] # the following checks are since nil values cause an error to be raised # whereas we want a nil to be wither treated as a zero or a blank if xx . nil? && yy . nil? res = 0 elsif xx . nil? res = - 1 elsif yy . nil? res = 1 else res = x [ e ] <=> y [ e ] end end break if res != 0 } res } ensure @model . insert 0 , header if header end end
sorts the model based on sort keys and reverse flags
 @sort_keys contains indices to sort on
 @reverse_flags is an array of booleans, true for reverse, nil or false for ascending
sorts the model based on sort keys and reverse flags