Juery method for solving tablesorter Chinese sorting and character range

Source: Internet
Author: User

This article mainly introduces juery to solve Tablesorter Chinese sorting and character range methods, examples of jquery for Tablesorter Chinese sorting and character range of the solution, the need for friends can refer to the

Tablesorter is a more excellent jquery plug-in table sorting plug-ins, I believe that we have used or have heard, I am not too much introduced here, detailed information can see the official website: http://tablesorter.com/docs/( One of the demo to do more complete).

In several projects using Tablesorter development, two types of sorting problems were identified, as follows:

The first problem is that you cannot sort the Chinese characters because the character size is compared to the Unicode value used when sorting the character, as follows:

JS Code

?

 1 2 3 4 5 6 7 8 9 10 11-12 function Sorttext (a,b) {return (a < b)?-1: ((a > B)? 1:0);}; function Sorttextdesc (a,b) {return (b < a)?-1: ((b > a)? 1:0);}; function Sorttext (a,b) {return (a < b)?-1: ((a > B)? 1:0);}; function Sorttextdesc (a,b) {return (b < a)?-1: ((b > a)? 1:0);};

And we want to get the result is sorted by pinyin, so we modify the code to the following code:

JS Code

?

 1 2 3 4 5 6 7 8 9 10 11-12 function Sorttext (a,b) {return a.localecompare (b);}; function Sorttextdesc (a,b) {return b.localecompare (a);}; function Sorttext (a,b) {return a.localecompare (b);}; function Sorttextdesc (a,b) {return b.localecompare (a);};

Localecompare method is a JS-band method, needless to say, words too literally know this method is based on the current area of the size of the character comparison, but this method can not handle pronunciation.

The second problem is that numeric data that is out of range cannot be sorted because of the distortion of the data value when a numeric type conversion occurs, for example:

JS Code

?

 1 2 3 4 5 6 7 8 9 10 Alert (parsefloat (' 9999999999999999 ')); 10000000000000000 Alert (parsefloat (' 10000000000000001 ')); 10000000000000000 Alert (parsefloat (' 10000000000000004 ')); 10000000000000004 Alert (parsefloat (' 10000000000000005 ')); 10000000000000004 Alert (parsefloat (' 10000000000000006 ')); 10000000000000006 Alert (parsefloat (' 9999999999999999 ')); 10000000000000000 Alert (parsefloat (' 10000000000000001 ')); 10000000000000000 Alert (parsefloat (' 10000000000000004 ')); 10000000000000004 Alert (parsefloat (' 10000000000000005 ')); 10000000000000004 Alert (parsefloat (' 10000000000000006 ')); 10000000000000006

Such deviations will make the ordering result inaccurate, in order to avoid this problem, should not use the original value for comparison, but should introduce weights, values from left to right, each digit corresponds to the weight of decreasing, and then according to the weight and the original value of the new values calculated for comparison, This only needs to modify the Formatfloat method to solve this problem.

JS Code

?

 1 2 3 4 5 This.formatfloat = function (s) {//TODO var i = parsefloat (s); return (isNaN (i))? 0:i;

I hope this article will help you with your jquery programming.

Related Keywords:
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.