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

given a 2-column table, first column must be sortable #83

Closed
listx opened this issue Feb 4, 2015 · 4 comments
Closed

given a 2-column table, first column must be sortable #83

listx opened this issue Feb 4, 2015 · 4 comments

Comments

@listx
Copy link
Contributor

listx commented Feb 4, 2015

I have this in my recruiting_partnership_datatable.rb:

class RecruitingPartnershipDatatable < AjaxDatatablesRails::Base

  def sortable_columns
    # Declare strings in this format: ModelName.column_name
    @sortable_columns ||= [
      'PartnershipSchedule.start_hour'
    ]
  end

  def searchable_columns
    # Declare strings in this format: ModelName.column_name
    @searchable_columns ||= [
    ]
  end

  private

  def data
    records.map do |r|
      [
        # comma separated list of the values for each cell of a table row
        # example: r.attribute,
        r.partnership.name,
        r.start_hour
      ]
    end
  end

  def get_raw_records
    # insert query here
    PartnershipSchedule.recruiting
  end

  # ==== Insert 'presenter'-like methods below if necessary
end

and also in my JS file:

    $("#recruiting-partnerships-table").dataTable
      processing: true
      serverSide: true
      pagingType: "full_numbers"
      ajax: $("#recruiting-partnerships-table").data("source")
      # disable search bar
      searching: false
      columns: [
        {sortable: false, searchable: false}
        {sortable: true, searchable: false}
      ]

This always crashes on initial load. If I then click on the 2nd column header to sort it, it works as expected. I supposed the initial sorting is messing it up.

The title of this issue is drawn from the current workaround, which is to switch the columns field values like this:

      columns: [
        {sortable: false, searchable: false}
        {sortable: true, searchable: false}
      ]

. Now it doesn't crash, but now the UI is wrong (click on first column header to sort by the 2nd column values).

@antillas21
Copy link
Collaborator

@listx please refer to this comment: #77 (comment) (to an issue by you 😄) where I mention that you start by the html view... so, basically if the html view has 2 columns, then your sortable and searchable columns methods should have 2 columns... if you only care about one of them (by specifying its sortable or searchable behavior through JS), then the other can be anything.

Realizing this (now) is (very, very, very) far from ideal... so I'm making a note to rework how columns are defined... but this will be available in another release.

@antillas21
Copy link
Collaborator

@listx Notes taken, and a new issue is open to rework how columns are declared inside the datatable class. See here for details: #84

@listx
Copy link
Contributor Author

listx commented Feb 6, 2015

Ah yes, I meant to reference #77 because you did say that ordering was important. I suppose we can close this issue for now and just move the discussion (if any --- this is not my specialty and I defer all judgments to you) to #84. Feel free to close --- I am not sure how you want to keep things organized in the issue tracker.

@antillas21
Copy link
Collaborator

OK, will close this issue for now.

I think that based on a scenario like the one you describe (which matches some scenarios described in other issues), a better API for handling columns (both sortable and searchable) is the right thing to do.

So, this will be addressed on #84 and targeted to be released on v.0.4.0 ... though as it will be a change in the API, not sure if it should be considered a major version bump (v.1.0.0)...

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

No branches or pull requests

2 participants