Skip to content

Q: col custom search + formatting #80

@Mr-Tao

Description

@Mr-Tao

I’ve found this brilliant gem a few days ago.

I have a cell with a JSON serialized array. I need to list these items in a DataTable cell and I also need to search through them. As easy as it is to implement each of these requirements, I have spent the better part of the day trying to figure out how to achieve both.

  • For the display part I did col :participants, partial: 'participants/table_item', partial_as: 'event' and put
    <ul>
      <% JSON::parse(event.participants).each do |p| %>
        <li><%= p %></li>
      <% end %>
    </ul>
    in the partial.
  • For the search part I’ve set up full text search in PostgreSQL so that Event.search_participants() does the searching and I can write:
    col :participants do |event|
      event.participants
    end.search do |collection, term, column, sql_column|
      collection = Event.search_participants(term)
    end

I would like to put these together, but I cannot as You cannot use partial: … with the block syntax
So I tried

col :participants do |event|
  tag.ul do
    JSON.parse(event.participants).each do |participant|
      tag.li participant
    end.search do |collection, term, column, sql_column|
      collection = Decision.search_participants(term)
    end
  end
end

but this render just an empty <ul></ul>. What am I doing wrong here?

Funnily I've skimmed through some old documentation too and it seems like overriding search_column method would suffice in the past.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions