Jquery-mobile-jqm-column-toggle-heading-groups

提供:Dev Guides
移動先:案内検索

列切り替えの見出しグループ

説明

*_data-mode = "columntoggle" _* 属性を使用して、見出しグループ名に従ってコンテンツを表示できます。

次の例は、jQuery Mobileフレームワークでの_columnトグルヘッダーグループ_の使用を示しています。

<!DOCTYPE html>
   <head>
      <title>Table Column Toggle Heading Group</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

      <style>
         .th-groups th {
            text-align: center;
            background-color: rgba(0,0,0,.1);
            border-right: 1px solid #fff;
         }

        /* Show priority 1 at 320px*/
         @media screen and (min-width: 20em) {
            th.ui-table-priority-1,
            td.ui-table-priority-1 {
               display: table-cell;
            }
         }

        /* Show priority 2 at 480px*/
         @media screen and (min-width: 30em) {
            th.ui-table-priority-2,
            td.ui-table-priority-2 {
               display: table-cell;
            }
         }

        /* Show priority 3 at 640px*/
         @media screen and (min-width: 40em) {
            th.ui-table-priority-3,
            td.ui-table-priority-3 {
               display: table-cell;
            }
         }

        /* Show priority 4 at 800px*/
         @media screen and (min-width: 50em) {
            th.ui-table-priority-4,
            td.ui-table-priority-4 {
               display: table-cell;
            }
         }

        /* Show priority 5 at 960px*/
         @media screen and (min-width: 60em) {
            th.ui-table-priority-5,
            td.ui-table-priority-5 {
               display: table-cell;
            }
         }

        /* Show priority 6 at 1200px*/
         @media screen and (min-width: 75em) {
            th.ui-table-priority-6,
            td.ui-table-priority-6 {
               display: table-cell;
            }
         }
      </style>
   </head>

   <body>
      <div data-role = "header">
         <h2>Header</h2>
      </div>

      <table data-role = "table" id = "table_columns" data-column-btn-theme = "b"
         data-column-popup-theme = "a" data-mode = "columntoggle" class = "table-stroke"
         data-column-btn-text = "Click here to display columns...">

         <thead>
            <tr class = "th-groups">
               <td></td>
               <th colspan = "3" data-priority = "5">INDIA</th>
               <th colspan = "3" data-priority = "4">AUSTRALIA</th>
               <th colspan = "3" data-priority = "2">ENGLAND</th>
            </tr>

            <tr>
               <th>Stadium</th>
               <th>Played</th>
               <th>Won</th>
               <th>Loss</th>
               <th>Played</th>
               <th>Won</th>
               <th>Loss</th>
               <th>Played</th>
               <th>Won</th>
               <th>Loss</th>
            </tr>
         </thead>

         <tbody>
            <tr>
               <th>Sydney</th>
               <td>20</td>
               <td>14</td>
               <td>6</td>
               <td>15</td>
               <td>10</td>
               <td>5</td>
               <td>10</td>
               <td>3</td>
               <td>7</td>
            </tr>

            <tr>
               <th>Eden Gardens</th>
               <td>10</td>
               <td>9</td>
               <td>1</td>
               <td>8</td>
               <td>3</td>
               <td>5</td>
               <td>9</td>
               <td>5</td>
               <td>4</td>
            </tr>

            <tr>
               <th>Oval</th>
               <td>12</td>
               <td>9</td>
               <td>3</td>
               <td>15</td>
               <td>3</td>
               <td>12</td>
               <td>20</td>
               <td>15</td>
               <td>5</td>
            </tr>
         </tbody>
      </table>

      <div data-role = "footer">
         <h2>Footer</h2>
      </div>

   </body>
</html>

出力

上記のコードがどのように機能するかを確認するために、次の手順を実行してみましょう-

  • 上記のHTMLコードを jqm_column_toggle_heading_groupsl ファイルとしてサーバーのルートフォルダーに保存します。
  • このHTMLファイルをhttp://localhost/jqm_column_toggle_heading_groupslとして開くと、次の出力が表示されます。