回答編集履歴
2
コメントを受けて追記
test
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
[Sorting plug-ins](https://www.datatables.net/plug-ins/sorting/)
|
6
6
|
|
7
7
|
|
8
|
+
|
9
|
+
|
8
10
|
|
9
11
|
### コメントを受けて追記
|
10
12
|
|
@@ -23,3 +25,47 @@
|
|
23
25
|
> That’s possible by adding the following code to the “Custom Commands” textfield in the “Features of the DataTables JavaScript library” section on the “Edit” screen of the table
|
24
26
|
|
25
27
|
[DataTables Sorting plugins | TablePress](https://tablepress.org/extensions/datatables-sorting-plugins/)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
### コメントを受けて追記
|
34
|
+
|
35
|
+
サンプルコードを挙げます。
|
36
|
+
|
37
|
+
```javascript
|
38
|
+
|
39
|
+
['a','b','c'].sort(function(a,b){
|
40
|
+
|
41
|
+
var testString = 'acb';
|
42
|
+
|
43
|
+
return testString.indexOf(a) - testString.indexOf(b);
|
44
|
+
|
45
|
+
})
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
/*
|
50
|
+
|
51
|
+
a,c,b
|
52
|
+
|
53
|
+
*/
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
参考:
|
60
|
+
|
61
|
+
> 指定された値が最初に現れたインデックスを返します。
|
62
|
+
|
63
|
+
[String.prototype.indexOf() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
> 文字列の代わりに数字を比較する場合、比較関数は単純に a から b を引けばよいでしょう。
|
70
|
+
|
71
|
+
[Array.prototype.sort() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
|
1
コメントを受けて追記
test
CHANGED
@@ -3,3 +3,23 @@
|
|
3
3
|
↓こちらを参考にしてみてください。
|
4
4
|
|
5
5
|
[Sorting plug-ins](https://www.datatables.net/plug-ins/sorting/)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
### コメントを受けて追記
|
10
|
+
|
11
|
+
DataTablesのソートをするのは↓のとおり比較的簡単なんですが、
|
12
|
+
|
13
|
+
[sort()](https://datatables.net/reference/api/sort())
|
14
|
+
|
15
|
+
demoのコードを見るとDataTablesのインスタンスがクロージャの中にあるので外部から触れなさそうです。
|
16
|
+
|
17
|
+
TablePressのドキュメントを見ても標準的なカスタマイズでは難しそうなので、PHPのソースから触る必要があるかと思います。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
または、ソート用のプラグインを使って、↓のようにオプションのパラメータを設定する方法でもいいかもしれません。
|
22
|
+
|
23
|
+
> That’s possible by adding the following code to the “Custom Commands” textfield in the “Features of the DataTables JavaScript library” section on the “Edit” screen of the table
|
24
|
+
|
25
|
+
[DataTables Sorting plugins | TablePress](https://tablepress.org/extensions/datatables-sorting-plugins/)
|