This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixed bug with incorrect sorting by 'tablesorter.js' plugin.
- Loading branch information
Marcin Brzeziński
committed
Feb 15, 2013
1 parent
956381e
commit 39e58f1
Showing
9 changed files
with
182 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
jQuery -> | ||
$.tablesorter.addParser | ||
id: 'polish' | ||
type: 'text' | ||
is: (s) -> | ||
false | ||
format: (s) -> | ||
s | ||
.toLowerCase() | ||
.replace(/\u0105/g, 'az') | ||
.replace(/\u0119/g, 'ez') | ||
.replace(/\u0107/g, 'cz') | ||
.replace(/\u0144/g, 'nz') | ||
.replace(/ó/g, 'oz') | ||
.replace(/\u0142/g, 'lz') | ||
.replace(/\u015b/g, 'sz') | ||
.replace(/\u017a/g, 'zz') #ź | ||
.replace(/\u017c/g, 'zzz') #ż | ||
|
||
lang = document.location.pathname.replace(/^\/([^\/]*).*$/, '$1') | ||
|
||
$.tablesorter.addParser | ||
id: 'amount' | ||
type: 'number' | ||
is: (s) -> | ||
false | ||
format: (s) -> | ||
if lang == "en" | ||
parseFloat s.replace(/,/g,'').replace("$",'') | ||
else if lang == "pl" | ||
parseFloat s.replace(',','.').replace(/\s/g,'') | ||
else | ||
s | ||
|
||
if $("#expenses_table").length | ||
$("#expenses_table").tablesorter | ||
headers: | ||
0: sorter: 'polish' | ||
1: sorter: 'amount' | ||
3: sorter: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#encoding: utf-8 | ||
require 'test_helper' | ||
|
||
class TablesorterTest < ActionDispatch::IntegrationTest | ||
def setup | ||
@user_pl = users(:user_with_locale_pl) | ||
@user_en = users(:user_with_locale_en) | ||
end | ||
|
||
test "should sort expenses by name" do | ||
allow_google_login_as(@user_pl) | ||
visit '/pl' | ||
log_in_pl | ||
click_on I18n.t('header.expenses', locale: 'pl') | ||
|
||
expenses_asc = [ | ||
'audi Q11', | ||
'Bułka', | ||
'bułki', | ||
'szlafrok', | ||
'śniadanie' | ||
] | ||
|
||
# ASC ORDER | ||
expenses_table_sort_by 1 | ||
expenses_table_check_order 1, expenses_asc | ||
|
||
# DESC ORDER | ||
expenses_table_sort_by 1 | ||
expenses_table_check_order 1, expenses_asc.reverse | ||
end | ||
|
||
test "should sort expenses by amount in pl format" do | ||
allow_google_login_as(@user_pl) | ||
visit '/pl' | ||
log_in_pl | ||
click_on I18n.t('header.expenses', locale: 'pl') | ||
|
||
expenses_amounts_asc = [ | ||
'1,01 zł', | ||
'1,12 zł', | ||
'12,00 zł', | ||
'12,40 zł', | ||
'12 000 121,12 zł' | ||
] | ||
|
||
# ASC ORDER | ||
expenses_table_sort_by 2 | ||
expenses_table_check_order 2, expenses_amounts_asc | ||
|
||
# DESC ORDER | ||
expenses_table_sort_by 2 | ||
expenses_table_check_order 2, expenses_amounts_asc.reverse | ||
end | ||
|
||
test "should sort expenses by amount in en format" do | ||
allow_google_login_as(@user_en) | ||
visit '/en' | ||
log_in_en | ||
click_on I18n.t('header.expenses', locale: 'en') | ||
|
||
expenses_amounts_asc = [ | ||
'$1.01', | ||
'$1.12', | ||
'$12.00', | ||
'$12.40', | ||
'$12,000,121.12' | ||
] | ||
|
||
# ASC ORDER | ||
expenses_table_sort_by 2 | ||
expenses_table_check_order 2, expenses_amounts_asc | ||
|
||
# DESC ORDER | ||
expenses_table_sort_by 2 | ||
expenses_table_check_order 2, expenses_amounts_asc.reverse | ||
end | ||
|
||
private | ||
def expenses_table_sort_by(column_number) | ||
find(:xpath, "//table[@id='expenses_table']/thead/tr[1]/th[#{column_number}]").click() | ||
end | ||
|
||
def expenses_table_check_order(column_number, array) | ||
array.each do |e| | ||
assert_equal e, find(:xpath, "//table[@id='expenses_table']/tbody/tr[#{array.index(e)+1}]/td[#{column_number}]").text | ||
end | ||
end | ||
end |
1 change: 0 additions & 1 deletion
1
app/assets/javascripts/tablesorter.js → vendor/assets/javascripts/tablesorter.js
Large diffs are not rendered by default.
Oops, something went wrong.