Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript Table Sort Problem - Column Hypothetical Results

Posted on 2009-05-19
17
Medium Priority
?
329 Views
Last Modified: 2012-06-27
See http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_24313854.html

Unfortunately, hypothetical results are still sorting alpha instead of numerical.

See http://www.mffais.com/ibm

and click on "Hypothetical Results"

Would like to know what to change to make it sort correctly for that column also.
0
Comment
Question by:surfsideinternet
  • 8
  • 5
  • 4
17 Comments
 
LVL 4

Expert Comment

by:ewest02
ID: 24428290
I noticed that the sort results differ depending on which column was sorted first, how many times a target column was sorted... I am wondering about the span.getAttribute( "sortdir")  line in the script. You do not have any span tags with that attribute -- you do have "sortarrow"
0
 

Author Comment

by:surfsideinternet
ID: 24428360
Okay, so how is the best way to correct it?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24428839
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:surfsideinternet
ID: 24433061
mplungjan,

In the original question, we said why we used this script instead of the original one.

"We would like to us this one to get dynamic alternating colors, nice arrows"
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24433073
Ok, then you need to take the object sort used in that script to sort your money string

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24433485
This one:

function(a,b) {
    aa = parseFloat(a[0].replace(/[^0-9.-]/g,''));
    if (isNaN(aa)) aa = 0;
    bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); 
    if (isNaN(bb)) bb = 0;
    return aa-bb;
  }

Open in new window

0
 

Author Comment

by:surfsideinternet
ID: 24437952
mplungjan,

Not sure what I am suppose to do with that function. The script has several functions depending on type of data. Can you tell me which lines in the script to change and what they should be.

The script is at: http://www.mffais.com/sorttable.js

Thanks
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24438332
Sorry, I will be offline a lot until monday.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24438363
Haha that sounded very nerdy - I meant, I will not be online a lot
0
 
LVL 4

Expert Comment

by:ewest02
ID: 24458063
Your regex that checks for numeric values does not handle the case that the minus sign can follow the £, $, ¬ ... symbols.   A number of the form -$12.34 will be properly detected as a numeric value. $-12.35 will be detected as a alphabetic string.

  --Eric
0
 

Author Comment

by:surfsideinternet
ID: 24458168
Eric,

What should the regex be then?
0
 
LVL 4

Expert Comment

by:ewest02
ID: 24458253
A related question:  Do you want the minus sign before or after the currency symbol (eg $)?

line 108 in the script:  if (itm.match(/^-?[£$¬Û¢´]\d/))
try
                  if (itm.match(/^-?[£$¬Û¢´]-?\d/))

note that is not a perfect solution.. It will match -$-1 ...you might want another regex to exactly match

 $- cases

                     if (itm.match(/^[£$¬Û¢´]-?\d/))

Here the regex looks for at most 1 minus sign following the currency symbol.




                 
0
 

Author Comment

by:surfsideinternet
ID: 24470050
ewset2,

I have made your modifications ( using   if (itm.match(/^-?[£$¬Û¢´]-?\d/)) ) to sorttable and you can use
http://test.mffais.com/123912 to see the effects of your suggestions.

That almost works, but some of the other columns are not working. Example, "Hypothetical Return" with a ending % and sometimes a - for not return or -13.4% for negative return. Anyway to get all the columns on that page to sort correctly?

Thanks

0
 
LVL 4

Accepted Solution

by:
ewest02 earned 1000 total points
ID: 24474679
113   if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)) sortfn = ts_sort_numeric;

It looks to me like this regex does not handle the case that there is white space between the last digit and the % sign. Try

113   if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?\s*%?$/)) sortfn = ts_sort_numeric;

to allow any number of white space characters between a digit and the trailing percent sign. I am not sure why there is a "E" at the start of the second grouping.

I am also wondering if your can loosen your criteria for how you detect a numeric value. Might it be simpler to detect a non-numeric value?

  --Eric
0
 

Author Comment

by:surfsideinternet
ID: 24477799
ewest02,

I would think it would be easier to detect non-numerical (excluding -,%,$). I think the only problem would be if sorting a column of names that have a - or a % as part of the name. I will try your suggestion above
0
 

Author Comment

by:surfsideinternet
ID: 24477851
ewest2,

I tried your latest suggestion and all appears to be working great. Thanks.
0
 

Author Closing Comment

by:surfsideinternet
ID: 31583287
Thank you, your final suggestion works like a charm.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question