Files
nairobi/app/assets/javascripts/table_sortable.js.coffee
Javi Martín b27855c1cf Use double quotes in CoffeeScript files
As we do in the rest of the application.

Note we cannot add a rule enforcing double quotes because CoffeeScript
Lint does not have such rule.
2019-03-06 11:41:21 +01:00

23 lines
713 B
CoffeeScript

App.TableSortable =
getCellValue: (row, index) ->
$(row).children("td").eq(index).text()
comparer: (index) ->
(a, b) ->
valA = App.TableSortable.getCellValue(a, index)
valB = App.TableSortable.getCellValue(b, index)
return if $.isNumeric(valA) and $.isNumeric(valB) then valA - valB else valA.localeCompare(valB)
initialize: ->
$("table.sortable th").click ->
table = $(this).parents("table").eq(0)
rows = table.find("tr:gt(0)").not("tfoot tr").toArray().sort(App.TableSortable.comparer($(this).index()))
@asc = !@asc
if !@asc
rows = rows.reverse()
i = 0
while i < rows.length
table.append rows[i]
i++
return