質問するログイン新規登録

回答編集履歴

2

コメントを受けて追記

2017/08/24 03:16

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア37568

answer CHANGED
@@ -2,6 +2,7 @@
2
2
  ↓こちらを参考にしてみてください。
3
3
  [Sorting plug-ins](https://www.datatables.net/plug-ins/sorting/)
4
4
 
5
+  
5
6
  ### コメントを受けて追記
6
7
  DataTablesのソートをするのは↓のとおり比較的簡単なんですが、
7
8
  [sort()](https://datatables.net/reference/api/sort())
@@ -10,4 +11,26 @@
10
11
 
11
12
  または、ソート用のプラグインを使って、↓のようにオプションのパラメータを設定する方法でもいいかもしれません。
12
13
  > 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
13
- [DataTables Sorting plugins | TablePress](https://tablepress.org/extensions/datatables-sorting-plugins/)
14
+ [DataTables Sorting plugins | TablePress](https://tablepress.org/extensions/datatables-sorting-plugins/)
15
+
16
+  
17
+ ### コメントを受けて追記
18
+ サンプルコードを挙げます。
19
+ ```javascript
20
+ ['a','b','c'].sort(function(a,b){
21
+ var testString = 'acb';
22
+ return testString.indexOf(a) - testString.indexOf(b);
23
+ })
24
+
25
+ /*
26
+ a,c,b
27
+ */
28
+ ```
29
+
30
+ 参考:
31
+ > 指定された値が最初に現れたインデックスを返します。
32
+ [String.prototype.indexOf() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
33
+
34
+  
35
+ > 文字列の代わりに数字を比較する場合、比較関数は単純に a から b を引けばよいでしょう。
36
+ [Array.prototype.sort() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)

1

コメントを受けて追記

2017/08/24 03:16

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア37568

answer CHANGED
@@ -1,3 +1,13 @@
1
1
  [TablePress の公式ページ](https://tablepress.org/)を見たところ、[DataTables](https://datatables.net/)を使っているようでしたので、ソートのカスタマイズが可能だと思います。
2
2
  ↓こちらを参考にしてみてください。
3
- [Sorting plug-ins](https://www.datatables.net/plug-ins/sorting/)
3
+ [Sorting plug-ins](https://www.datatables.net/plug-ins/sorting/)
4
+
5
+ ### コメントを受けて追記
6
+ DataTablesのソートをするのは↓のとおり比較的簡単なんですが、
7
+ [sort()](https://datatables.net/reference/api/sort())
8
+ demoのコードを見るとDataTablesのインスタンスがクロージャの中にあるので外部から触れなさそうです。
9
+ TablePressのドキュメントを見ても標準的なカスタマイズでは難しそうなので、PHPのソースから触る必要があるかと思います。
10
+
11
+ または、ソート用のプラグインを使って、↓のようにオプションのパラメータを設定する方法でもいいかもしれません。
12
+ > 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
13
+ [DataTables Sorting plugins | TablePress](https://tablepress.org/extensions/datatables-sorting-plugins/)