pisze skrypt w jquery umozliwiajacy sortowanie tabeli i mam maly problem, gdyz do sortowania daty w formacie YYYY-MM-DD
przerobilem jakis inny skrypt jquery i cos sie popierniczylo, ze nie sortuje:
<?php
$.fn.alternateRowColors = function() {
$('tbody tr:odd', this).removeClass('even').addClass('odd');
$('tbody tr:even', this).removeClass('odd').addClass('even');
return this;
};
$(document).ready(function() {
var alternateRowColors = function($table) {
$('tbody tr:odd', $table).removeClass('even').addClass('odd');
$('tbody tr:even', $table).removeClass('odd').addClass('even');
};
$
('table.sortable').each(function() { var $table = $(this);
$table.alternateRowColors($table);
$
('th', $table).each(function(column
) { var findSortKey;
if($(this).is('.sort-alpha')) {
findSortKey = function($cell) {
return $cell.find('.sort-key').text().toUpperCase() + ' ' + $cell.text().toUpperCase();
};
}
else if($(this).is('.sort-numeric')) {
findSortKey = function($cell) {
var key = parseFloat
($cell.text
().replace
(/^
[^d
.]*/, '')); };
}
else if($(this).is('.sort-date')) {
findSortKey = function($cell) {
var dateTest = [
{ regExp:/^(0?[1-9]|1[012])([- /.])(0?[1-9]|[12][0-9]|3[01])([- /.])((dd)?dd)$/, d:3, m:1, y:5 }, // mdy
{ regExp:/^(0?[1-9]|[12][0-9]|3[01])([- /.])(0?[1-9]|1[012])([- /.])((dd)?dd)$/, d:1, m:3, y:5 }, // dmy
{ regExp:/^(dddd)([- /.])(0?[1-9]|1[012])([- /.])(0?[1-9]|[12][0-9]|3[01])$/, d:5, m:3, y:1 } // ymd
];
var start, cnt = 0, numFormats = dateTest.length;
while(cnt < numFormats) {
start = (cnt + (favourDMY ? numFormats + 1 : numFormats)) % numFormats;
if(dateIn.match(dateTest[start].regExp)) {
res = dateIn.match(dateTest[start].regExp);
y = res[dateTest[start].y];
m = res[dateTest[start].m];
d = res[dateTest[start].d];
if(m.length == 1) m = "0" + String(m);
if(d.length == 1) d = "0" + String(d);
if(y.length != 4) y = (parseInt(y) < 50) ? "20" + String(y) : "19" + String(y);
return Date.parse
(y
+String
(m
)+d
; };
cnt++;
};
return 0;
};
}
if(findSortKey) {
$(this).addClass ('clickable').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
}).click(function() {
var rows = $table.find('tbody > tr').get();
$
.each(rows
, function(index
, row
) { row.sortKey = findSortKey($(row).children('td').eq(column));
});
rows
.sort(function(a
, b
) { if(a.sortKey < b.sortKey) return -1;
if(a.sortKey > b.sortKey) return 1;
return 0;
});
$
.each(rows
, function(index
, row
) { $table.children('tbody').append(row);
row.sortKey = null;
});
$table.alternateRowColors($table);
});
}
});
});
});
?>
moze ktos zauwazy w czym problem ? (chodzi wylacznie o sortowanie wg daty)