{"action":"created","issue":{"url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails/issues/228","repository_url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails","labels_url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails/issues/228/labels{/name}","comments_url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails/issues/228/comments","events_url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails/issues/228/events","html_url":"https://github.com/jbox-web/ajax-datatables-rails/issues/228","id":233504178,"number":228,"title":"Allow again overriding filter_records, sort_records...","user":{"login":"panmari","id":719020,"avatar_url":"https://avatars1.githubusercontent.com/u/719020?v=4","gravatar_id":"","url":"https://api.github.com/users/panmari","html_url":"https://github.com/panmari","followers_url":"https://api.github.com/users/panmari/followers","following_url":"https://api.github.com/users/panmari/following{/other_user}","gists_url":"https://api.github.com/users/panmari/gists{/gist_id}","starred_url":"https://api.github.com/users/panmari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panmari/subscriptions","organizations_url":"https://api.github.com/users/panmari/orgs","repos_url":"https://api.github.com/users/panmari/repos","events_url":"https://api.github.com/users/panmari/events{/privacy}","received_events_url":"https://api.github.com/users/panmari/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-06-05T06:22:43Z","updated_at":"2017-11-08T16:23:45Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Currently, when overriding for example `filter_records` in a custom datatable, it's ignored due to 'load_orm_extension' being called on initialize, which overrides the custom method by the one provided in the orm.\r\n\r\n    def initialize(view, options = {})\r\n      @view    = view\r\n      @options = options\r\n      load_orm_extension\r\n    end\r\n\r\nAccording to the rails generator datatable template, such use should be possible:\r\n```ruby\r\n  # ==== These methods represent the basic operations to perform on records\r\n  # and feel free to override them\r\n\r\n  # def filter_records(records)\r\n  # end\r\n\r\n  # def sort_records(records)\r\n  # end\r\n\r\n  # def paginate_records(records)\r\n  # end\r\n```\r\n\r\nAs a workaround I'm currently overriding `retrieve_records` in my custom datatable\r\n\r\n```ruby\r\n  def retrieve_records\r\n    records = fetch_records\r\n    records = filter_records_with_my_awesome_custom_logic(records)\r\n    records = sort_records(records)     if datatable.orderable?\r\n    records = paginate_records(records) if datatable.paginate?\r\n    records\r\n  end\r\n\r\n``` "},"comment":{"url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails/issues/comments/342870844","html_url":"https://github.com/jbox-web/ajax-datatables-rails/issues/228#issuecomment-342870844","issue_url":"https://api.github.com/repos/jbox-web/ajax-datatables-rails/issues/228","id":342870844,"user":{"login":"GUI","id":12112,"avatar_url":"https://avatars1.githubusercontent.com/u/12112?v=4","gravatar_id":"","url":"https://api.github.com/users/GUI","html_url":"https://github.com/GUI","followers_url":"https://api.github.com/users/GUI/followers","following_url":"https://api.github.com/users/GUI/following{/other_user}","gists_url":"https://api.github.com/users/GUI/gists{/gist_id}","starred_url":"https://api.github.com/users/GUI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GUI/subscriptions","organizations_url":"https://api.github.com/users/GUI/orgs","repos_url":"https://api.github.com/users/GUI/repos","events_url":"https://api.github.com/users/GUI/events{/privacy}","received_events_url":"https://api.github.com/users/GUI/received_events","type":"User","site_admin":false},"created_at":"2017-11-08T16:23:45Z","updated_at":"2017-11-08T16:23:45Z","author_association":"NONE","body":"One thing to note about @panmari's workaround is that it doesn't affect the `recordsFiltered` count returned by the API, since the default `records_filtered_count` implementation is still calling the original `filter_records` method (rather than the custom one). While you could also override `records_filtered_count` in a similar fashion, here's a slightly different approach to this workaround that forces the replacement `filter_records` method to be re-defined after the ORM's version:\r\n\r\n```ruby\r\nclass ExampleDatatable < AjaxDatatablesRails::Base\r\n  private\r\n\r\n  def load_orm_extension\r\n    super\r\n    extend CustomOverrides\r\n  end\r\n\r\n  module CustomOverrides\r\n    def filter_records(records)\r\n      records = super(records)\r\n      records.where(:other => \"stuff\")\r\n    end\r\n  end\r\nend\r\n```"}}
{"actor":{"display_login":"GUI"}}