Data sorting sounds like only php tutorials, ASP tutorials, SQL to achieve, today we provide a data can be sorted at the client JS code, the need for friends can refer to.
function Sortcells (event) {
var obj = Event.target;
var count = 0; Count is the number of clicks recorded, depending on the parity in ascending or descending order
if (!obj.getattribute ("Clickcount")) {
Obj.setattribute ("Clickcount", 0);
} else {
Count = parseint (Obj.getattribute ("Clickcount"));
count++;
Obj.setattribute ("Clickcount", count);
}
var table = Event.target.parentNode.parentNode;
if (Table.nodeName.localeCompare ("THEAD") = = 0) {
if (Table.parentNode.nodeName.localeCompare ("table") = = 0) {
Table = Table.parentnode;
} else {
Return
}
else if (Table.nodeName.localeCompare ("tbody") = = 0) {
if (Table.parentNode.nodeName.localeCompare ("table") = = 0) {
Table = Table.parentnode;
} else {
Return
}
else if (table.nodeName.localeCompare ("table") = = 0) {
} else {
Return
}
var colnum;
for (x = 0; x < table.rows (1). cells.length x + +) {
if (Event.target.innerText.localeCompare (table.rows (0). cells[x].innertext) = = 0) {
Colnum = x;
Break
}
}
var column = table.rows (1). Cells.length;
var row = Table.rows.length;
var Ar = new Array (row-1);
for (x = 0; x < row-1 + +) {
AR[X] = new Array (column);
}
for (x = 1; x < row; + +) {
for (y = 0; y < column; y++) {
Ar[x-1][y] = table.rows (x). Cells (y). InnerHTML;
}
}
This can be sorted to localize the string
/* if ((count%2) = = 0) {
Ar.sort (function (A, b) {
Return B[colnum].localecompare (A[colnum])
});
} else {
Ar.sort (function (A, b) {
Return A[colnum].localecompare (B[colnum])
});
} */
var temp;
for (x = 0; x < row-1 + +) {
for (y = 1; y < row-1; y++) {
temp = ar[y-1];
if ((count% 2) = = 0) {
if (parseint (Ar[y-1][colnum]) >= parseint (Ar[y][colnum])) {
AR[Y-1] = Ar[y];
Ar[y] = temp;
}
} else {
if (parseint (Ar[y-1][colnum]) <= parseint (Ar[y][colnum])) {
AR[Y-1] = Ar[y];
Ar[y] = temp;
}
}
}
}
for (x = 1; x < row; + +) {
for (y = 0; y < column; y++) {
Table.rows (x). Cells (y). InnerHTML = Ar[x-1][y];
}
}
count++;
}