/    Sign up×
Community /Pin to ProfileBookmark

TableSort problem

Hey,

I am trying to modify a script that sorts a table. The problem is that it sorts text fields correctly but is treating number fields like text and isn’t sorting them correctly. So I want to write an if else statement saying that if it’s a number then parseFloat it and if not then just compare as a normal string. I tried using isNan but it kept saying Object expected. The code for this function looks like this, in this state it sorts number fields correctly but does nothing to fields that are not numbers. Taking out the ParseFloat will sort text fields correctly but not numbers. How can I do both? thanks!:

function compareByColumn(nCol, bDescending) {
var c = nCol;
var d = bDescending;

function _compare(n1, n2) {
var v;

if ((parseFloat(getInnerText(n1.cells[c]))) < (parseFloat(getInnerText(n2.cells[c]))))
v = (d) ? -1 : +1;

else if (parseFloat(getInnerText(n1.cells[c])) > (parseFloat(getInnerText(n2.cells[c]))))
v = (d) ? +1 : -1;

else
v = 0;

return v;

}

return _compare;
}

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @haunsolo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...