Use DataTables to sort Chinese

Source: Internet
Author: User

Osort is an array of sort types, ' chinese-asc ' is the sort of a type that is defined by itself (*-ASC | | *-desc) name
The plugin should be sorted according to the type of content in the table (string, number, Chinese),
If you sort by Chinese type then use osort[' Chinese-asc ' and osort[' Chinese-desc '] method
Osort corresponding function inside the custom comparison method
jquery.fn.datatableext.osort[' chinese-asc ' = function (x, y) {
JavaScript comes with the Chinese comparison function, the specific use of self-access to understand
return X.localecompare (y);
};

jquery.fn.datatableext.osort[' chinese-desc ' = function (x, y) {
return Y.localecompare (x);
};

Atypes is an array of plug-in storage table content types
A regular expression of the Reg assignment to determine if it is a Chinese character
The return value is push to the atypes array, and the array is scanned when sorted, and ' Chinese ' calls the above two methods. Returns null default is ' string '
JQuery.fn.dataTableExt.aTypes.push (function (sData) {
var reg =/^[\u4e00-\u9fa5]{0,}$/;
if (Reg.test (SData)) {
Return ' Chinese ';
}
return null;
});

Front-end use is also the most important Oh ~ Method has is not how to use it is very headache ...

"Columndefs":
[


{"Atypes": "Chinese-asc", "atargets": [0]} refers to the 0th column of the table if the 0th column is Chinese

] So easy

Use DataTables to sort Chinese

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.