jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
587 stars 228 forks source link

Sort by different field of the object. #412

Closed rahulthakur1390 closed 1 year ago

rahulthakur1390 commented 2 years ago

gem 'ajax-datatables-rails', '~> 1.2.0'

def view_columns
    @view_columns ||= {
      select: { source: 'Node.record_guid' },
      ip: { source: 'Node.ip' },
      dns: { source: 'Node.dns' },
      os: { source: 'Node.os' },
      domain: { source: 'Node.domain' },
      action: { source: 'Node.record_guid' }
    }
  end

  def initialize(params, opts = {})
    @view = opts[:view_context]
    super
  end

  def data
    records.map do |record|
      {
        select: datatable_check_box(record.record_guid, 'selected_nodes', "assessment_nodes #{@class_name}"),
        ip: record.ip,
        dns: record.dns,
        os: record.os,
        domain: record.domain,
        action: action_columns(record)
      }
    end
  end

I want to display ip column but when I sort ip column it should sort by ip_conversion field. ip_conversion is an another field of the record object and ip_conversion is not displaying. Is there any way to do this?

image

Thanks in advance. Please help me.

rahulthakur1390 commented 1 year ago

Got it the answer is given in the gem description so closed this.