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
585 stars 228 forks source link

No result for custom column when using search bar #340

Closed arlharis closed 4 years ago

arlharis commented 4 years ago

Hi, I'm stuck with this problem for almost a whole day now. My datatable is working properly then I decided to use custom columns.

the result is not appear when I type 'Paid' or 'Pending' at the search bar. But if I type true or false, the result appear.

I also tried the example that uses Arel syntax but still same error. Please advise. Im using rails 6

purchase_datatable.rb

  def view_columns
    @view_columns ||= {
      .
      .
      .
      paid: { source: 'Purchase.paid', cond: change_data },
     .
     .
     .
    }
  end

  def data
    records.map do |record|
      {
        .
        .
        .
        paid: record.paid ? 'Paid' : 'Pending' , ## The data is in boolean
        .
        .
        .
      }
     end
   end

  def change_data
    ->(column, value) { column.table[column.field].eq(column.search.value.to_s + '') }
  end