Skip to content

Conversation

mebezac
Copy link
Collaborator

@mebezac mebezac commented Jan 27, 2015

Take an example, there is a table with 6 columns. The first 4 columns are searchable/orderable, as is the 6th. The 5th column displayed on the table is just a link, or some other data that doesn't need ordered. So there are 5 orderable columns and 6 columns displayed.

def sortable_columns
    # list columns inside the Array in string dot notation.
    # Example: 'users.email'
    @sortable_columns ||= ["training_search_entries.name",
                          "training_search_entries.date_and_time",
                          "training_search_entries.location",
                          "training_search_entries.spots",
                          "training_search_entries.status"
                          ]
  end

  def searchable_columns
    # list columns inside the Array in string dot notation.
    # Example: 'users.email'
    @searchable_columns ||= ["training_search_entries.name",
                          "training_search_entries.date_and_time",
                          "training_search_entries.location",
                          "training_search_entries.spots",
                          "training_search_entries.status"
                          ]
  end

If one makes the 5th column not orderable through the DataTables API - https://datatables.net/reference/option/columns.orderable

EX:

"columnDefs": [
    { "orderable": false, "targets": 4 }
  ]

image

Then when clicking on the 6th column to order it, it tries to find the 6th orderable column, but there is none, so it generates a faulty query.

This PR remedies this by identify from the params which columns have not had their ordering shut off with the DataTables API and uses that to correctly identify which column the user is trying to sort by.

@antillas21
Copy link
Collaborator

@mebezac 😄 most appreciated! I will merge this as soon as you fix the typos for diplayed to displayed (which look more like what you intend to mean)

@mebezac
Copy link
Collaborator Author

mebezac commented Jan 27, 2015

Haha, my bad :)

antillas21 added a commit that referenced this pull request Jan 27, 2015
Allow disabling of columns orderable to play nice with sortable_columns
@antillas21 antillas21 merged commit c90c64c into jbox-web:master Jan 27, 2015
@antillas21
Copy link
Collaborator

@mebezac Thank you very much for your contribution. We are slowly working on a new release for the gem, and this feature will definitely come in handy.

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