Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Search For TableScreen (take 2) #641

Merged
merged 9 commits into from
Apr 2, 2015
Merged

Conversation

jamonholmgren
Copy link
Owner

Check #639 for specifics. Pasting @sxross 's description here.


This enables TableScreen to be backward compatible if the user wants to use default search on title or search_text, but allows custom search to be specified. E.g.:

class MySearchable < PM::TableScreen
  searchable placeholder: "Search events", with: -> (cell, search_string) {
    return cell[:properties][:event_name].downcase.strip.include?(search_string.downcase.strip)
  }
end

For those wanting code that does not resist refactoring quite so much, you can specify a method:

class MySearchable < PM::TableScreen
  searchable placeholder: "Search events", with: :search_method

  # other stuff
  def search_method
    return cell[:properties][:event_name].downcase.strip.include?(search_string.downcase.strip)
  end
  }
end

Real world examples would probably be more complex.

sxross and others added 9 commits February 24, 2015 15:31
- Instead of passing the controller into the table data,
  pass a proc bound in the context of the controller.
  Thanks @jasonholmgren.

- Remove params as second argument to search -- the params will
  have been resolved when the table_data is allocated.

- Which one wins: If the user passes more than one proc or symbol
  using the params hash, the behavior is undefined, but the last
  one evaluated is the one that becomes the custom action. Because
  hashes are not necessarily ordered sets, order is meaningless
  in this context.
jamonholmgren added a commit that referenced this pull request Apr 2, 2015
Custom Search For TableScreen (take 2)
@jamonholmgren jamonholmgren merged commit f7a2584 into version-2.3 Apr 2, 2015
@jamonholmgren jamonholmgren deleted the search_with branch April 2, 2015 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants