Skip to content

Commit f9303b4

Browse files
committed
Implement @haferje 's Date parse/sort support in coffee script #9
1 parent 4092e4f commit f9303b4

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

coffee/sortable.coffee

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ sortable =
7070
getColumnType: (table, i) ->
7171
for row in table.tBodies[0].rows
7272
text = sortable.getNodeValue row.cells[i]
73-
return sortable.types.numeric if text isnt '' and text.match(numberRegExp)
73+
if text isnt ''
74+
if text.match(numberRegExp)
75+
return sortable.types.numeric
76+
if not isNaN Date.parse(text)
77+
return sortable.types.date
78+
7479
return sortable.types.alpha
7580

7681
getNodeValue: (node) ->
@@ -94,6 +99,15 @@ sortable =
9499
compare: (a, b) ->
95100
a[0].localeCompare b[0]
96101

102+
date:
103+
defaultSortDirection: 'ascending'
104+
compare: (a, b) ->
105+
aa = Date.parse(a[0])
106+
bb = Date.parse(b[0])
107+
aa = 0 if isNaN(aa)
108+
bb = 0 if isNaN(bb)
109+
aa - bb
110+
97111
setTimeout sortable.init, 0
98112

99113
window.Sortable = sortable

js/sortable.js

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)