Sha256: 153ad4fe2bb12d078128333d8d23b1c7f4333af767eab867009f7c994fbc6222

Contents?: true

Size: 773 Bytes

Versions: 35

Compression:

Stored size: 773 Bytes

Contents

module Effective
  module EffectiveDatatable
    module Helpers

      # When we order by Array, it's already a string.
      # This gives us a mechanism to sort numbers as numbers
      def convert_to_column_type(table_column, value)
        if value.html_safe? && value.kind_of?(String) && value.start_with?('<')
          value = ActionView::Base.full_sanitizer.sanitize(value)
        end

        case table_column[:type]
        when :number, :price, :decimal, :float, :percentage
          (value.to_s.gsub(/[^0-9|\.]/, '').to_f rescue 0.00) unless value.kind_of?(Numeric)
        when :integer
          (value.to_s.gsub(/\D/, '').to_i rescue 0) unless value.kind_of?(Integer)
        else
          ; # Do nothing
        end || value
      end

    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
effective_datatables-2.6.21 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.12.2 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.12.1 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.12.0 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.11.2 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.11.1 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.11.0 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.10.0 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.9.0 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.8.0 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.7.0 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.20 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.19 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.18 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.17 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.16 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.15 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.14 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.13 app/models/effective/effective_datatable/helpers.rb
effective_datatables-2.6.12 app/models/effective/effective_datatable/helpers.rb