Help:Sortable tables/ja

PD 注意: このページを編集すると、編集内容が CC0 のもとで公開されることに同意したと見なされます。詳細はパブリック・ドメインのヘルプ ページを参照してください。 PD

ソート可能な表を作成するには、表に sortable クラスを追加します。 このクラスを追加すると、各ヘッダー セル内のヘッダーの横に矢印が表示されます。 (下記のを参照) 矢印をクリックすると、選択した列に基づいて表の行が並び替えられます。 矢印を連続してクリックすると、次のパターンで並び順が変わります。昇順、降順、ソートなし。 異なる列の矢印を Shift キーを押しながらクリックすると、二次的な並び替えが行えます。

Shift キーを押しながらの各クリックで、クリックされた列に基づいた二次的な並び替えが行われます。この機能は三次およびそれ以上の並び替えにも適用されます。

ソートのモード

項目は、ヘッダーの下の最初の数行のデータ型に基づいて並べ替えられます。 データ型を決定するために、ページの読み込み時にヘッダーの下にある最初の 5 つの空ではない行が調べられ、最適な形式が選択されます。 矛盾が発生することがあります。 さらに、特定の列では、下記の関連する節で説明されているように、ソート順を強制できます。

現在、spansup のようなタグはデータ型の決定に影響しませんが、参照番号や表示されるコメントは影響します。

日時

さまざまな日付の書式に対応しています。各地域の言語での月名を含む書式にも対応しています。 例えば、ドイツ語版ウィキペディアでは「16. März 2010」は「2010-03-16」として適切にソートされます。

ピリオド、カンマ、アポストロフィ、スラッシュ (. , ' /) のようなさまざまな区切り文字を含むさまざまな数値の書式に対応しています。 英語版ウィキペディアは通常、米国の日付書式を使用します (例: month-day-year 月-日-年)。

数字

スクリプトは、小数点として「.」「,」を使用した数値や、「e」「E」を使用した科学的表記の数値も検出できます。 デフォルトでは、数字は英数字順にソートされます。つまり、数値ではなく文字列としてソートされます。 これにより、「9」が「10」の後に来るなど、予期しない並び順になる可能性があります。ただし、このデフォルトの動作は必要に応じて上書きできます。 ただし、このデフォルトの動作は必要に応じて上書きできます。

テキスト

When lists are sorted alphabetically by MediaWiki, the order of characters is sorted with Intl.Collator. This sorts accented characters correctly based on PageContentLanguage.

Android Webviews don't support this, so fallback to the old sort routine is required. The order is the same as the order of Unicode code points. Some of the more common characters are ordered as follows (in ascending order):

 
 !"#$ %&'()*+,-./0123456789 : ;<=> ?@ABC
DEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg
hijklmnopqrstuvwxyz{|}~
 
¡¢£¤¥¦§¨©ª« ¬
­
®¯°±²³´µ·¸¹º »¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐ
ÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóô
õö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘ
ęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļ
ĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠ
šŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƏƒǺǻǼ
ǽǾǿȘșȚțəˆˇˉ˘˙˚˛˜˝΄΅Ά·ΈΉΊΌΎΏΐΑΒΓΔΕΖΗΘ
ΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμν
ξοπρςστυφχψωϊϋόύώЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВ
ГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеж
зийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњ
ћќѝўџҐґ
  Ω

Forcing the sort mode of a column

Adding data-sort-type="..." to the header lets you control how a table is sorted. This feature is derived from tablesorter.com (webarchive). Valid values for "data-sort-type" include the following which are not case-sensitive:

  • currency
  • number
  • isoDate
  • time
  • IPAddress
  • usLongDate
  • date
  • text
  • url

例:

Wikitext

{|class="wikitable sortable"
!data-sort-type="date"| 日付 !! 名前 !! 身長 !!data-sort-type="number"| 給与
|-
| 01.10.1977 || Smith || 1.85 || 1,000.000
|-
| 11.6.1972 || Ray || 1.89 || 900.000
|-
| 1.9.1992 || Bianchi || 1.72 || 2,000.50
|}

Rendering

日付名前身長給与
01.10.1977Smith1.851,000.000
11.6.1972Ray1.89900.000
1.9.1992Bianchi1.722,000.50

Specifying a sort key

You can adjust how cells are sorted or parsed if needed. For instance, if a cell says "John Smith" but should be sorted under "Smith", you can use the data-sort-value="..." attribute to achieve this.

Wikitext

{|class="wikitable sortable"
! 氏名 !! 身長
|-
|data-sort-value="Smith, John"| John Smith || 1.85
|-
|data-sort-value="Ray, Ian"| Ian Ray || 1.89
|-
|data-sort-value="Bianchi, Zachary"| Zachary Bianchi || 1.72
|}

Rendering

氏名身長
John Smith1.85
Ian Ray1.89
Zachary Bianchi1.72

Controlling sorting and display

To ensure certain text isn't sorted but still displayed, use data-sort-type="...". You can then append additional text after values, like "200 approx" or "100<sup style="color:blue" title="link to Reference">[1]". An empty cell sorts as "-Infinity". If a cell contains a range of dates or numbers (for example, from 2 to 5), use data-sort-value="...".

The first column sorts plain numbers. The second column sorts more content as numbers using data-sort-type="number" in the table header. The fourth column defines numeric sort values independently of cell content using data-sort-value="...".

numbers data-sort-type="number" data-sort-type="number"
-8e3-8 e3-8 e3
-3e-3-3 e-3-3 e-3
2.0002-5 km²data-sort-value="3.5"2-5 km²
3.993.99 km²3.99 km²
44 km²4 km²
90 %90 Percentdata-sort-value="90"about 90 Percent
1E2100[1]100[1]
1,000,000.01 000 000.0data-sort-value="1e6"one Million

The way commas (,) and decimal points (.) are displayed in Mediawiki depends on the language settings. Currency symbols and the percentage (%) symbol are sorted numerically based on these settings.

currencies
$ 9
$ 80
$ 70
$ 600
currencies
9 €
80 €
70 €
600 €
currencies
£ 9
£ 80
£ 70
£ 600
currencies
¥ 9
¥ 80
¥ 70
¥ 600
percent
9 %
80 %
70 %
600 %
numbers
−7e270
-1.4285714285714E-13
999e9
7e270

Secondary sort key

You can sort data by columns, with Column A as the primary sort key. If Column A has equal values, use Column B as the secondary key. Click Column A's sort button once or twice, then while holding shift, click Column B's sort button once or twice for further refinement.

例:

Click on the "Text" column first, then hold down the shift key and click on the "Numbers" column. You'll notice that the items are sorted based on text first and then numbers.

Numbers テキスト 日付 通貨 その他のテキスト
4a01.Jan.20054.20row 1
5a05/12/20067.15row 2
1b02-02-20045.00row 3
1a02-02-20045.00row 4
2x13-apr-2005row 5
2a13-apr-2005row 6
3a17.aug.20066.50row 7
3z25.aug.20062.30row 8
3z28.aug.20065.50row 9
3z31.aug.20063.77row 10
3z01.sep.20061.50row 11
Bottom

Additional features

Excluding the last row from sorting

You can skip sorting the last row of a table by marking it with class="sortbottom". You can also exclude it from sorting by declaring it as a footer with an exclamation mark (!).

Wikitext

{|class="wikitable sortable"
! 名 !! 姓 !! 身長
|-
| John || Smith || 1.85
|-
| Ron || Ray || 1.89
|-
| Mario || Bianchi || 1.72
|- class="sortbottom"
! !! 平均: || 1.82
|}

Rendering

身長
JohnSmith1.85
RonRay1.89
MarioBianchi1.72
平均:1.82

Excluding the first row from sorting

You can exclude the first row by using the class="sorttop".

Wikitext

{|class="wikitable sortable"
! 名 !! 姓 !! 身長
|- class="sorttop"
! !! 平均: || 1.82
|-
| John || Smith || 1.85
|-
| Ron || Ray || 1.89
|-
| Mario || Bianchi || 1.72
|}

Rendering

身長
平均:1.82
JohnSmith1.85
RonRay1.89
MarioBianchi1.72

Making a column unsortable

To stop a column from being sortable, use class="unsortable" in its header cell's attributes.

Wikitext

{|class="wikitable sortable"
! Numbers !! 英字 !! 日付 !! 通貨 !!class="unsortable"| ソート不可
|-
| 1 || Z || 02-02-2004 || 5.00 || This
|-
| 2 || y || 13-apr-2005 || || Column
|-
| 3 || X || 17.aug.2006 || 6.50 || Is
|-
| 4 || w || 01.Jan.2005 || 4.20 || Unsortable
|-
| 5 || V || 05/12/2006 || 7.15 || See?
|-
! 合計: 15 !! !! !! 合計: 29.55 !!
|-
|}

Rendering

Numbers英字日付通貨ソート不可
1Z02-02-20045.00This
2y13-apr-2005Column
3X17.aug.20066.50Is
4w01.Jan.20054.20Unsortable
5V05/12/20067.15See?
合計: 15合計: 29.55Original example

Keeping some rows together

To allow an uncolumned row to always stay beneath the columned row above it, no matter how you sort them, use class="expand-child" in the row's attribute.

Wikitext

{| class="wikitable sortable"
!style="width:9em"| 国 !!data-sort-type="number"| 面積
|-
| フランス
| 674 843 km²
|- class="expand-child" style="font-size:85%; line-height:1.2; color:gray"
|colspan="2"| パリにはエッフェル塔があります。
|-
| イギリス
| 242 495 km²
|- class="expand-child" style="font-size:85%; line-height:1.2; color:gray"
|colspan="2"| イギリスではユーロで支払えません。
|- class="expand-child" style="font-size:85%; line-height:1.2; color:gray"
|colspan="2"| さらに、車は道路の左側通行です。
|-
| ドイツ
| 357 168 km²
|- class="expand-child" style="font-size:85%; line-height:1.2; color:gray"
|colspan="2"| ドイツにはかつての東ドイツ (DDR) も含みます。
|}

Rendering

面積
フランス 674 843 km²
パリにはエッフェル塔があります。
イギリス 242 495 km²
イギリスではユーロで支払えません。
さらに、車は道路の左側通行です。
ドイツ 357 168 km²
ドイツにはかつての東ドイツ (DDR) も含みます。

If you put in data-sort-value the same content as above row, keep this rows also together. The original mutual order of these rows is preserved. A better way for this is class expand-child, see above #Keeping some rows together.

Example where data-sort-value is used is the case for the rows about the Netherlands:

{|class="wikitable sortable"
! 国/州 !! 首都
|-
| フランス || パリ
|-
| オランダ || アムステルダム
|-
|data-sort-value="オランダ"| 南ホラント州 ||data-sort-value="アムステルダム"| デン・ハーグ
|-
| イギリス || ロンドン
|}
Country/provinceCapital
フランスパリ
オランダアムステルダム
南ホラント州デン・ハーグ
イギリスロンドン

Special dates

To represent years Before the Common Era (BCE) subtract the BCE year from 10,000. For instance, -62 BCE would be 10,000 - 62 = 9938.

For example, September 23, 62 BCE would be represented as 9938-09-23.

If a table column has incomplete dates, sorting won't be an issue. If only a year and month are provided, it's sorted before the first day of that month. Similarly, if only a year is given, it's sorted before the first month or day of that year.

Wikitext

{| class="wikitable sortable"
|-
! 日付
|-
| 2022-01-01
|-
| 2023-12-31
|-
| 2024
|-
| 2024-04
|-
| 2024-04-00
|-
| 2024-05
|-
| 2024-05-00
|}

Rendering

日付
2022-01-01
2023-12-31
2024
2024-04
2024-04-00
2024-05
2024-05-00

Using #time

You can use the parser function #time and HTML tags to display a specific date range. By adding the HTML tag <span style="display:none">&{{#expr:3e11+{{#time:U|..}}}}</span> before the displayed date, you can manipulate the way the date is shown. This method works for dates between January 1, 111 CE, and December 31, 9999 CE, using the proleptic Gregorian calendar. The added value ensures all values are positive and uniform in length. Placing "&" before the expression forces string sorting mode.

You can input dates and times using any PHP format for date and time. Remember, if you're specifying just a year, you must include a month (usually January) in the background.

For example using date:

入力された日時 テキスト 日時の解釈、非表示のソートキーを含む ソートキーを表示した入力 非表示のソートキーがある入力 UNIX 日時
010203&301749517323 10 6月 2025 01:02:03&301749517323 010203&301749517323 0102031749517323
1/2&301735776000 02 1月 2025 00:00:00&301735776000 1/2&301735776000 1/21735776000
1/2/3&301041465600 02 1月 2003 00:00:00&301041465600 1/2/3&301041465600 1/2/31041465600
1-2-2003&301044057600 01 2月 2003 00:00:00&301044057600 1-2-2003&301044057600 1-2-20031044057600
1-2-3&300981158400 03 2月 2001 00:00:00&300981158400 1-2-3&300981158400 1-2-3981158400
2007&301167609600 01 1月 2007 00:00:00&301167609600 2007&301167609600 20071167609600
1 Jan 111, 00:00:00&241335609600 01 1月 0111 00:00:00&241335609600 1 Jan 111, 00:00:00&241335609600 1 Jan 111, 00:00:00-58664390400
31 Dec 9999, 23:59:59&553402300799 31 12月 9999 23:59:59&553402300799 31 Dec 9999, 23:59:59&553402300799 31 Dec 9999, 23:59:59253402300799
Sep 1970&300020995200 01 9月 1970 00:00:00&300020995200 Sep 1970&300020995200 Sep 197020995200
1970&300000000000 01 1月 1970 00:00:00&300000000000 1970&300000000000 19700
Jun 2007or later&301180656000 01 6月 2007 00:00:00 or later&301180656000 Jun 2007 or later&301180656000 Jun 2007 or later1180656000 or later
Jun 2007perhaps earlier&301180656000 01 6月 2007 00:00:00 perhaps earlier&301180656000 Jun 2007 perhaps earlier&301180656000 Jun 2007 perhaps earlier1180656000 perhaps earlier
2007-6&301180656000 01 6月 2007 00:00:00&301180656000 2007-6&301180656000 2007-61180656000
Jun 2007&301180656000 01 6月 2007 00:00:00&301180656000 Jun 2007&301180656000 Jun 20071180656000
4 Jun 2007&301180915200 04 6月 2007 00:00:00&301180915200 4 Jun 2007&301180915200 4 Jun 20071180915200
3 Jul 2007&301183420800 03 7月 2007 00:00:00&301183420800 3 Jul 2007&301183420800 3 Jul 20071183420800
12 Aug 2006&301155340800 12 8月 2006 00:00:00&301155340800 12 Aug 2006&301155340800 12 Aug 20061155340800
1 Mar 2006 -1day&301141084800 28 2月 2006 00:00:00&301141084800 1 Mar 2006 -1day&301141084800 1 Mar 2006 -1day1141084800
1 Mar 2008 -1day&301204243200 29 2月 2008 00:00:00&301204243200 1 Mar 2008 -1day&301204243200 1 Mar 2008 -1day1204243200
1 Mar 2010 -1day&301267315200 28 2月 2010 00:00:00&301267315200 1 Mar 2010 -1day&301267315200 1 Mar 2010 -1day1267315200
1 Mar 1900 -1day&297796022400 28 2月 1900 00:00:00&297796022400 1 Mar 1900 -1day&297796022400 1 Mar 1900 -1day-2203977600
1 Mar 1600 -1day&288329001600 29 2月 1600 00:00:00&288329001600 1 Mar 1600 -1day&288329001600 1 Mar 1600 -1day-11670998400
Jun 1607&288557875200 01 6月 1607 00:00:00&288557875200 Jun 1607&288557875200 Jun 1607-11442124800
20250610142400&301749565440 10 6月 2025 14:24:00&301749565440 20250610142400&301749565440 202506101424001749565440
yesterday&301749427200 09 6月 2025 00:00:00&301749427200 yesterday&301749427200 yesterday1749427200
today&301749513600 10 6月 2025 00:00:00&301749513600 today&301749513600 today1749513600
tomorrow&301749600000 11 6月 2025 00:00:00&301749600000 tomorrow&301749600000 tomorrow1749600000
1week&301750170241 17 6月 2025 14:24:01&301750170241 1week&301750170241 1week1750170241
-1week&301748960641 03 6月 2025 14:24:01&301748960641 -1week&301748960641 -1week1748960641
1day&301749651841 11 6月 2025 14:24:01&301749651841 1day&301749651841 1day1749651841
-1day&301749479041 09 6月 2025 14:24:01&301749479041 -1day&301749479041 -1day1749479041
1month&301752157441 10 7月 2025 14:24:01&301752157441 1month&301752157441 1month1752157441
-1month&301746887041 10 5月 2025 14:24:01&301746887041 -1month&301746887041 -1month1746887041
1year&301781101441 10 6月 2026 14:24:01&301781101441 1year&301781101441 1year1781101441
-1year&301718029441 10 6月 2024 14:24:01&301718029441 -1year&301718029441 -1year1718029441
1000year&333306474241 10 6月 3025 14:24:01&333306474241 1000year&333306474241 1000year33306474241
10000month&328047047041 10 10月 2858 14:24:01&328047047041 10000month&328047047041 10000month28047047041
1000000day&388149565441 08 5月 4763 14:24:01&388149565441 1000000day&388149565441 1000000day88149565441
10000000hour&337749565441 28 3月 3166 06:24:01&337749565441 10000000hour&337749565441 10000000hour37749565441
1000000000minute&361749565441 08 10月 3926 01:04:01&361749565441 1000000000minute&361749565441 1000000000minute61749565441
100000000000second&401749565441 26 4月 5194 00:10:41&401749565441 100000000000second&401749565441 100000000000second101749565441
7980year&Expression error: Unexpected < operator. エラー: #time が対応しているのは 9999 年までです。&Expression error: Unexpected < operator. 7980year&Expression error: Unexpected < operator. 7980yearエラー: #time が対応しているのは 9999 年までです。
-1890year&242106867841 10 6月 0135 14:24:01&242106867841 -1890year&242106867841 -1890year-57893132159
Mon&301750032000 16 6月 2025 00:00:00&301750032000 Mon&301750032000 Mon1750032000
Tue&301749513600 10 6月 2025 00:00:00&301749513600 Tue&301749513600 Tue1749513600
Wed&301749600000 11 6月 2025 00:00:00&301749600000 Wed&301749600000 Wed1749600000
Thu&301749686400 12 6月 2025 00:00:00&301749686400 Thu&301749686400 Thu1749686400
Fri&301749772800 13 6月 2025 00:00:00&301749772800 Fri&301749772800 Fri1749772800
Sat&301749859200 14 6月 2025 00:00:00&301749859200 Sat&301749859200 Sat1749859200
Sun&301749945600 15 6月 2025 00:00:00&301749945600 Sun&301749945600 Sun1749945600
&Expression error: Unexpected < operator. エラー: 日時が無効です。&Expression error: Unexpected < operator.&Expression error: Unexpected < operator. エラー: 日時が無効です。
unknown&Expression error: Unexpected < operator. エラー: 日時が無効です。&Expression error: Unexpected < operator. unknown&Expression error: Unexpected < operator. unknownエラー: 日時が無効です。

To use dates before 111 CE, add a multiple of 400 (like 6000) to all years. This shifts the range to start from January 1st, -5889, at 00:00:00, and ends on December 31st, 3999, at 23:59:59, without altering the calendar system.

関連項目:

Cell spanning multiple rows/cells

A cell that extends across multiple rows or columns is considered equivalent to having multiple cells with identical values.

rowspan
日付名前身長
01.10.1977Smith1.85
11.06.1972Adams
01.09.1992Bianchi1.72
colspan
ABC
A 2 1
B 1 3
C 2

Any missing cells at the end of a row will turn into empty cells after the first sort.

Colspanned cells

Sort modes are detected separately for each column containing colspanned cells. You can set a sort mode for all colspanned columns by including data-sort-type in the header.

To implement separate sort keys for each column within a colspanned cell, utilize a CSS trick described here: Ensure an equal number of cells in each row for sortable columns. If there's a mismatch, all columns become sortable. This rule should apply up to and including the last sortable column. However, employing a CSS workaround allows for a difference between the displayed number of cells in a row and the formal count. For instance, two formal cells can appear as one by adjusting the width of the first column, shifting the content of the second cell to the left, increasing its width by the same measure, and concealing the cell border that would typically be visible. Concealed sort keys enable managing the sorting order of specific rows in relation to each column.

例:

CountryCapital
フランス パリ
Sorting with respect to the first column this row sorts like Z, with respect to the second column like M
イギリス ロンドン

Static column

To make a static column, like one with row numbers, use two tables placed next to each other. Make sure each row in both tables has the same height. You can also use w:Template:Static row numbers to generate row numbers implicitly using CSS rather than creating another table.

Number
1
2
首都
オランダアムステルダム (ハーグが政府の所在地であるにもかかわらず)
フランスパリ

The formatting can be modified to present everything in a unified table. If a row is too short for the text in a cell, the browser will expand it, disrupting the alignment.

Default order

You can't show a table sorted by a column without the user clicking on it. By default, table rows appear in the order as the wikitext. To display a table sorted by a specific column, you'll need to arrange the wikitext accordingly. One way of doing this is:

  1. Rearrange the table's wikitext without the top and bottom lines.
  2. Replace the cell separators with a unique code that doesn't contain a "|" by using "find and replace".
  3. Replace any pipes within table cells with a code, and then substitute that code with a newline character preceded by it (indicating the start of a new row).
  4. Use the Sort module on Special:ExpandTemplates. To sort the items between the pipes and produce the desired separator, expand templates and add {{#invoke:Sort|f||- | (with the newline) before and }} after the wikitext.
  5. Delete the items that begin with "-" and a newline.
  6. Change the temporary codes for the cell separators and pipes inside the cells to restore them.

This sorting method relies on the wikitext in each row, primarily sorting by the content of the first column. The second column serves as a secondary key. However, wikitext codes in the first column cells before the content can impact the order.

You can also use Snippets/Sort table on reload to automatically sort the table when it loads using JavaScript.

Persistent sort states using cookies

You can save the state of sortable tables across reloads using Snippets/Persistent sort order.

関連項目

その他の例:

Category:Help/ja
Category:Help/ja