question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Q: col custom search + formatting

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
matt-riemercommented, May 15, 2018

Is your category a belongs_to object? Or just a string?

That query makes me think datatables is detecting it like a string ILIKE %93% but the decision_category_id makes me think it’s a belongs_to? Not sure what’s up there.

Something like this should work tho:

col(:category, search: { as: :select, collection: EventCategory.all, multiple: true }) do |obj|
  obj.category.to_s
end

or

col(:category_id, as: :integer, search: { as: :select, collection: EventCategory.all, multiple: true }) do |obj|
  obj.category.to_s
end

Or maybe the join syntax could work

datatable do
  col 'category.name'
end

collection do
   Event.joins(:category).all
end
0reactions
matt-riemercommented, May 21, 2018

thanks for coming back with the solution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table | Quasar Framework
It's generally called a datatable. It packs the following main features: Filtering; Sorting; Single / Multiple rows selection with custom selection actions ...
Read more >
Implementing search box | Programmable Search Engine
In the Control Panel click the search engine you want to use. Click Setup in the sidebar, and then click the Basics tab....
Read more >
Use conditional formatting to highlight information
How to use conditional formatting in Excel to visually explore, analyze, and identify patterns and trends.
Read more >
Custom Format Columns in SalesLogix Web (and Linking to ...
In this scenario, we'll just use a sample of adding a hyperlink into the Account Contacts grid to do a Google search on...
Read more >
Excel conditional formatting formulas based on another cell
Enter the formula in the corresponding box. Click the Format… button to choose your custom format. Switch between the Font, Border and Fill ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found