Data Table - 图1

Data Table

Data tables display sets of raw data. They usually appear in desktop enterprise products

Data Table Layout

Common Data Table layout could be treated as the following:

  1. <div class="data-table">
  2. <table>
  3. <thead>
  4. <tr>
  5. <th class="label-cell">Desert (100g serving)</th>
  6. <th class="numeric-cell">Calories</th>
  7. ...
  8. <th class="tablet-only">Comment</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <tr>
  13. <td class="label-cell">Frozen yogurt</td>
  14. <td class="numeric-cell">159</td>
  15. ...
  16. <td class="tablet-only">I like it!</td>
  17. </tr>
  18. ...
  19. </tbody>
  20. </table>
  21. </div>

Within Card:

  1. <div class="data-table card">
  2. <table>
  3. <thead>
  4. ...
  5. </thead>
  6. <tbody>
  7. ...
  8. </tbody>
  9. </table>
  10. </div>

Where

  • data-table - main Data Table wrapper. Required
    • table - table itself. Required
      • thead - table head
      • tbody - table body. Required
      • label-cell - main label cell (only one such kind of cell per row, usually first cell)
      • numeric-cell - cell to display numeric data (right-aligned)
      • tablet-only - additional class to show this cell/column only on wide tablet devices (iPad)

Pagination Footer

  1. <div class="card data-table">
  2. <table>
  3. <thead>
  4. <tr>
  5. <th class="label-cell">Desert (100g serving)</th>
  6. <th class="numeric-cell">Calories</th>
  7. <th class="numeric-cell">Fat (g)</th>
  8. <th class="numeric-cell">Carbs</th>
  9. <th class="numeric-cell">Protein (g)</th>
  10. </tr>
  11. </thead>
  12. <tbody>
  13. <tr>
  14. <td class="label-cell">Frozen yogurt</td>
  15. <td class="numeric-cell">159</td>
  16. <td class="numeric-cell">6.0</td>
  17. <td class="numeric-cell">24</td>
  18. <td class="numeric-cell">4.0</td>
  19. </tr>
  20. ...
  21. </tbody>
  22. </table>
  23. <div class="data-table-footer">
  24. <div class="data-table-rows-select">
  25. Per page:
  26. <div class="input input-dropdown">
  27. <select>
  28. <option value="5">5</option>
  29. <option value="10">10</option>
  30. <option value="25">25</option>
  31. <option value="all">All</option>
  32. </select>
  33. </div>
  34. </div>
  35. <div class="data-table-pagination">
  36. <span class="data-table-pagination-label">1-5 of 10</span>
  37. <a href="#" class="link disabled">
  38. <i class="icon icon-prev color-gray"></i>
  39. </a>
  40. <a href="#" class="link">
  41. <i class="icon icon-next color-gray"></i>
  42. </a>
  43. </div>
  44. </div>
  45. </div>

Where

  • data-table-footer - data table footer main element
    • data-table-rows-select - container with amount per page select
    • data-table-pagination - container with information about current page and prev/next navigation buttons
      • data-table-pagination-label - current paging label

Selectable Rows

  1. <div class="data-table data-table-init card">
  2. <table>
  3. <thead>
  4. <tr>
  5. <th class="checkbox-cell">
  6. <label class="checkbox">
  7. <input type="checkbox"/>
  8. <i class="icon-checkbox"></i>
  9. </label>
  10. </th>
  11. <th class="label-cell">Desert (100g serving)</th>
  12. <th class="numeric-cell">Calories</th>
  13. ...
  14. <th class="numeric-cell">Protein (g)</th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <tr>
  19. <td class="checkbox-cell">
  20. <label class="checkbox">
  21. <input type="checkbox"/>
  22. <i class="icon-checkbox"></i>
  23. </label>
  24. </td>
  25. <td class="label-cell">Frozen yogurt</td>
  26. <td class="numeric-cell">159</td>
  27. ...
  28. <td class="numeric-cell">4.0</td>
  29. </tr>
  30. ...
  31. </tbody>
  32. </table>
  33. </div>

Where

  • data-table-init - additional class to enable JavaScript action required for selectable rows
  • Checkbox cell. Such cell in table header will select/deselect all rows in table body:

    1. <td class="checkbox-cell">
    2. <label class="checkbox">
    3. <input type="checkbox"/>
    4. <i class="icon-checkbox"></i>
    5. </label>
    6. </td>

Inputs In Table Head

Such tables are widely used in admin interfaces for filtering or search data

  1. <div class="card data-table">
  2. <table>
  3. <thead>
  4. <tr>
  5. <th class="input-cell">
  6. <span class="table-head-label">ID</span>
  7. <div class="input" style="width: 50px">
  8. <input type="number" placeholder="Filter">
  9. </div>
  10. </th>
  11. <th class="input-cell">
  12. <span class="table-head-label">Name</span>
  13. <div class="input">
  14. <input type="text" placeholder="Filter">
  15. </div>
  16. </th>
  17. ...
  18. <th class="input-cell">
  19. <span class="table-head-label">Gender</span>
  20. <div class="input input-dropdown">
  21. <select>
  22. <option value="All">All</option>
  23. <option value="Male">Male</option>
  24. <option value="Female">Female</option>
  25. </select>
  26. </div>
  27. </th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <tr>
  32. <td>1</td>
  33. <td>John Doe</td>
  34. <td>john@doe.com</td>
  35. <td>Male</td>
  36. </tr>
  37. ...
  38. </tbody>
  39. </table>
  40. </div>

Where

  • input-cell - additional class on table cell required to display input

  • <span class="table-head-label"> - input label

  • <div class="input"> - input container

Table Title/Header

When data table is used within Card it is possible to use additional data table title with actions in card header.

With title and actions

  1. <div class="data-table data-table-init card">
  2. <!-- Card Header -->
  3. <div class="card-header">
  4. <!-- Table title -->
  5. <div class="data-table-title">Nutrition</div>
  6. <!-- Table actions -->
  7. <div class="data-table-actions">
  8. <a class="link icon-only">
  9. <i class="icon f7-icons if-not-md">sort</i>
  10. <i class="icon material-icons md-only">sort</i>
  11. </a>
  12. <a class="link icon-only">
  13. <i class="icon f7-icons if-not-md">more_vertical_round</i>
  14. <i class="icon material-icons md-only">more_vert</i>
  15. </a>
  16. </div>
  17. </div>
  18. <!-- Card Content -->
  19. <div class="card-content">
  20. <table>
  21. <thead>
  22. <tr>
  23. <th class="checkbox-cell">
  24. <label class="checkbox">
  25. <input type="checkbox">
  26. <i class="icon-checkbox"></i>
  27. </label>
  28. </th>
  29. <th class="label-cell">Desert (100g serving)</th>
  30. <th class="numeric-cell">Calories</th>
  31. ...
  32. </tr>
  33. </thead>
  34. <tbody>
  35. <tr>
  36. <td class="checkbox-cell">
  37. <label class="checkbox">
  38. <input type="checkbox">
  39. <i class="icon-checkbox"></i>
  40. </label>
  41. </td>
  42. <td class="label-cell">Frozen yogurt</td>
  43. <td class="numeric-cell">159</td>
  44. ...
  45. </tr>
  46. ...
  47. </tbody>
  48. </table>
  49. </div>
  50. </div>

Where

  • data-table-title - table title
  • data-table-actions - main table actions

Different actions on select

  1. <div class="data-table data-table-init card">
  2. <!-- Card header -->
  3. <div class="card-header">
  4. <!-- Default table header -->
  5. <div class="data-table-header">
  6. <!-- Default table title -->
  7. <div class="data-table-title">Nutrition</div>
  8. <!-- Default table actions -->
  9. <div class="data-table-actions">
  10. <a class="link icon-only">
  11. <i class="icon f7-icons if-not-md">sort</i>
  12. <i class="icon material-icons md-only">sort</i>
  13. </a>
  14. <a class="link icon-only">
  15. <i class="icon f7-icons if-not-md">more_vertical_round</i>
  16. <i class="icon material-icons md-only">more_vert</i>
  17. </a>
  18. </div>
  19. </div>
  20. <!-- Selected table header -->
  21. <div class="data-table-header-selected">
  22. <!-- Selected table title -->
  23. <div class="data-table-title-selected"><span class="data-table-selected-count"></span> items selected</div>
  24. <!-- Selected table actions -->
  25. <div class="data-table-actions">
  26. <a class="link icon-only">
  27. <i class="icon f7-icons if-not-md">trash</i>
  28. <i class="icon material-icons md-only">delete</i>
  29. </a>
  30. <a class="link icon-only">
  31. <i class="icon f7-icons if-not-md">more_vertical_round</i>
  32. <i class="icon material-icons md-only">more_vert</i>
  33. </a>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="card-content">
  38. <table>
  39. <thead>
  40. <tr>
  41. <th class="checkbox-cell">
  42. <label class="checkbox">
  43. <input type="checkbox">
  44. <i class="icon-checkbox"></i>
  45. </label>
  46. </th>
  47. <th class="label-cell">Desert (100g serving)</th>
  48. <th class="numeric-cell">Calories</th>
  49. ...
  50. </tr>
  51. </thead>
  52. <tbody>
  53. <tr>
  54. <td class="checkbox-cell">
  55. <label class="checkbox">
  56. <input type="checkbox">
  57. <i class="icon-checkbox"></i>
  58. </label>
  59. </td>
  60. <td class="label-cell">Frozen yogurt</td>
  61. <td class="numeric-cell">159</td>
  62. ...
  63. </tr>
  64. ...
  65. </tbody>
  66. </table>
  67. </div>
  68. </div>

Where

  • data-table-header - default table header. Visible when there are no selected rows
  • data-table-header-selected - selected table header. Visible when there are selected rows
  • data-table-selected-count - count of selected table rows. Number will be placed here by JavaScript

Alternate header with row actions

  1. <div class="data-table data-table-init card">
  2. <div class="card-header">
  3. <!-- Table links/actions -->
  4. <div class="data-table-links">
  5. <a class="link">Add</a>
  6. <a class="link">Remove</a>
  7. </div>
  8. <!-- Table actions -->
  9. <div class="data-table-actions">
  10. <a class="link icon-only">
  11. <i class="icon f7-icons if-not-md">sort</i>
  12. <i class="icon material-icons md-only">sort</i>
  13. </a>
  14. <a class="link icon-only">
  15. <i class="icon f7-icons if-not-md">more_vertical_round</i>
  16. <i class="icon material-icons md-only">more_vert</i>
  17. </a>
  18. </div>
  19. </div>
  20. <div class="card-content">
  21. <table>
  22. <thead>
  23. <tr>
  24. <th class="checkbox-cell">
  25. <label class="checkbox">
  26. <input type="checkbox">
  27. <i class="icon-checkbox"></i>
  28. </label>
  29. </th>
  30. <th class="label-cell">Desert (100g serving)</th>
  31. <th class="numeric-cell">Calories</th>
  32. ...
  33. <th></th>
  34. </tr>
  35. </thead>
  36. <tbody>
  37. <tr>
  38. <td class="checkbox-cell">
  39. <label class="checkbox">
  40. <input type="checkbox">
  41. <i class="icon-checkbox"></i>
  42. </label>
  43. </td>
  44. <td class="label-cell">Frozen yogurt</td>
  45. <td class="numeric-cell">159</td>
  46. ...
  47. <td class="actions-cell">
  48. <a class="link icon-only">
  49. <i class="icon f7-icons if-not-md">compose</i>
  50. <i class="icon material-icons md-only">edit</i>
  51. </a>
  52. <a class="link icon-only">
  53. <i class="icon f7-icons if-not-md">trash</i>
  54. <i class="icon material-icons md-only">delete</i>
  55. </a>
  56. </td>
  57. </tr>
  58. ...
  59. </tbody>
  60. </table>
  61. </div>
  62. </div>

Where

  • data-table-links - alternate/additional table actions
  • actions-cell - action links/icons cell

Sortable

  1. <div class="data-table data-table-init card">
  2. <div class="card-header">
  3. <div class="data-table-title">Nutrition</div>
  4. <div class="data-table-actions">
  5. <a class="link icon-only">
  6. <i class="icon f7-icons if-not-md">sort</i>
  7. <i class="icon material-icons md-only">sort</i>
  8. </a>
  9. <a class="link icon-only">
  10. <i class="icon f7-icons if-not-md">more_vertical_round</i>
  11. <i class="icon material-icons md-only">more_vert</i>
  12. </a>
  13. </div>
  14. </div>
  15. <div class="card-content">
  16. <table>
  17. <thead>
  18. <tr>
  19. <th class="checkbox-cell">
  20. <label class="checkbox">
  21. <input type="checkbox">
  22. <i class="icon-checkbox"></i>
  23. </label>
  24. </th>
  25. <th class="label-cell sortable-cell sortable-cell-active">Desert (100g serving)</th>
  26. <th class="numeric-cell sortable-cell">Calories</th>
  27. <th class="numeric-cell sortable-cell">Fat (g)</th>
  28. <th class="numeric-cell sortable-cell">Carbs</th>
  29. <th class="numeric-cell sortable-cell">Protein (g)</th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. <tr>
  34. <td class="checkbox-cell">
  35. <label class="checkbox">
  36. <input type="checkbox">
  37. <i class="icon-checkbox"></i>
  38. </label>
  39. </td>
  40. <td class="label-cell">Frozen yogurt</td>
  41. <td class="numeric-cell">159</td>
  42. <td class="numeric-cell">6.0</td>
  43. <td class="numeric-cell">24</td>
  44. <td class="numeric-cell">4.0</td>
  45. </tr>
  46. ...
  47. </tbody>
  48. </table>
  49. </div>
  50. </div>

Where

  • sortable-cell - additional class to make cell/column is sortable
  • sortable-cell-active - additional class to specify active/default sortable cell/column
  • sortable-asc - additional class to specify current sorting as ascending (default)
  • sortable-desc - additional class to specify current sorting as descending

Note, there is no actual sortable logic provided by framework. Actual sorting logic should be realized manually

Collapsible

The following table will be collapsed to kind of List View on small screens:

  1. <div class="card data-table data-table-collapsible data-table-init">
  2. <div class="card-header">
  3. <div class="data-table-title">Nutrition</div>
  4. <div class="data-table-actions">
  5. <a class="link icon-only">
  6. <i class="icon f7-icons if-not-md">sort</i>
  7. <i class="icon material-icons md-only">sort</i>
  8. </a>
  9. <a class="link icon-only">
  10. <i class="icon f7-icons if-not-md">more_vertical_round</i>
  11. <i class="icon material-icons md-only">more_vert</i>
  12. </a>
  13. </div>
  14. </div>
  15. <div class="card-content">
  16. <table>
  17. <thead>
  18. <tr>
  19. <th class="label-cell">Desert (100g serving)</th>
  20. <th class="numeric-cell">Calories</th>
  21. ...
  22. <th class="numeric-cell">Protein (g)</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td class="label-cell">Frozen yogurt</td>
  28. <td class="numeric-cell">159</td>
  29. ...
  30. <td class="numeric-cell">4.0</td>
  31. </tr>
  32. ...
  33. </tbody>
  34. </table>
  35. </div>
  36. </div>

Where

  • data-table-collapsible - additional table class to enable collapsible logic. Note that “data-table-init” class is also required for this.

Data Table App Methods

In case you add data table dynamically and you need such selecting rows or switching headers logic you need to init it manually. Let’s look at related app methods to work with data table:

app.dataTable.create(parameters)- create Data Table instance

  • parameters - object. Object with data table parameters

Method returns created Data Table’s instance

app.dataTable.destroy(el)- destroy Data Table instance

  • el - HTMLElement or string (with CSS Selector) or object. Data Table element or Data Table instance to destroy.

app.dataTable.get(el)- get Data Table instance by HTML element

  • el - HTMLElement or string (with CSS Selector). Data Table element.

Method returns Data Table’s instance

Data Table Parameters

Now let’s look at list of available parameters we need to create Data Table:

ParameterTypeDefaultDescription
elHTMLElementData Table element. Can be useful if you already have Data Table element in your HTML and want to create new instance using this element

CSS Variables

Below is the list of related CSS variables (CSS custom properties).

Note that commented variables are not specified by default and their values is what they fallback to in this case.

  1. :root {
  2. --f7-table-head-font-size: 12px;
  3. --f7-table-body-font-size: 14px;
  4. --f7-table-footer-font-size: 12px;
  5. --f7-table-input-height: 24px;
  6. --f7-table-input-font-size: 14px;
  7. --f7-table-collapsible-cell-padding: 15px;
  8. --f7-table-link-icon-only-icon-size: 20px;
  9. --f7-table-sortable-icon-color: #000;
  10. }
  11. :root .theme-dark,
  12. :root.theme-dark {
  13. --f7-table-cell-border-color: #282829;
  14. --f7-table-sortable-icon-color: #fff;
  15. --f7-table-input-text-color: #fff;
  16. }
  17. .ios {
  18. --f7-table-head-font-weight: 600;
  19. --f7-table-head-text-color: #8e8e93;
  20. --f7-table-head-cell-height: 44px;
  21. --f7-table-head-icon-size: 18px;
  22. --f7-table-body-cell-height: 44px;
  23. --f7-table-cell-border-color: #c8c7cc;
  24. --f7-table-cell-padding-vertical: 0px;
  25. --f7-table-cell-padding-horizontal: 15px;
  26. --f7-table-edge-cell-padding-horizontal: 15px;
  27. --f7-table-label-cell-padding-horizontal: 15px;
  28. --f7-table-checkbox-cell-width: 22px;
  29. /* --f7-table-actions-cell-link-color: var(--f7-theme-color); */
  30. --f7-table-selected-row-bg-color: #f7f7f8;
  31. /* --f7-table-actions-link-color: var(--f7-theme-color); */
  32. --f7-table-title-font-size: 17px;
  33. --f7-table-title-font-weight: 600;
  34. --f7-table-card-header-height: 64px;
  35. --f7-table-footer-height: 44px;
  36. --f7-table-footer-text-color: #8e8e93;
  37. --f7-table-input-text-color: #000;
  38. }
  39. .ios .theme-dark,
  40. .ios.theme-dark {
  41. --f7-table-selected-row-bg-color: #363636;
  42. }
  43. .md {
  44. --f7-table-head-font-weight: 500;
  45. --f7-table-head-text-color: rgba(0, 0, 0, 0.54);
  46. --f7-table-head-cell-height: 56px;
  47. --f7-table-head-icon-size: 16px;
  48. --f7-table-body-cell-height: 48px;
  49. --f7-table-cell-border-color: rgba(0, 0, 0, 0.12);
  50. --f7-table-cell-padding-vertical: 0px;
  51. --f7-table-cell-padding-horizontal: 28px;
  52. --f7-table-edge-cell-padding-horizontal: 24px;
  53. --f7-table-label-cell-padding-horizontal: 24px;
  54. --f7-table-checkbox-cell-width: 18px;
  55. --f7-table-actions-cell-link-color: rgba(0, 0, 0, 0.54);
  56. --f7-table-selected-row-bg-color: #f5f5f5;
  57. --f7-table-actions-link-color: rgba(0, 0, 0, 0.54);
  58. --f7-table-title-font-size: 20px;
  59. --f7-table-title-font-weight: 400;
  60. --f7-table-card-header-height: 64px;
  61. --f7-table-footer-height: 56px;
  62. --f7-table-footer-text-color: rgba(0, 0, 0, 0.54);
  63. --f7-table-input-text-color: #212121;
  64. }
  65. .md .theme-dark,
  66. .md.theme-dark {
  67. --f7-table-head-text-color: rgba(255, 255, 255, 0.54);
  68. --f7-table-footer-text-color: rgba(255, 255, 255, 0.54);
  69. --f7-table-selected-row-bg-color: rgba(255, 255, 255, 0.05);
  70. --f7-table-actions-cell-link-color: rgba(255, 255, 255, 0.54);
  71. --f7-table-actions-link-color: rgba(255, 255, 255, 0.54);
  72. }
  73. .aurora {
  74. --f7-table-link-icon-only-icon-size: 18px;
  75. --f7-table-head-font-weight: 400;
  76. --f7-table-head-text-color: rgba(0, 0, 0, 0.6);
  77. --f7-table-head-cell-height: 32px;
  78. --f7-table-head-icon-size: 18px;
  79. --f7-table-body-cell-height: 32px;
  80. --f7-table-cell-border-color: rgba(0, 0, 0, 0.12);
  81. --f7-table-cell-padding-vertical: 5px;
  82. --f7-table-cell-padding-horizontal: 10px;
  83. --f7-table-edge-cell-padding-horizontal: 15px;
  84. --f7-table-label-cell-padding-horizontal: 15px;
  85. --f7-table-checkbox-cell-width: 22px;
  86. /* --f7-table-actions-cell-link-color: var(--f7-theme-color); */
  87. --f7-table-selected-row-bg-color: rgba(0, 0, 0, 0.03);
  88. /* --f7-table-actions-link-color: var(--f7-theme-color); */
  89. --f7-table-title-font-size: 14px;
  90. --f7-table-title-font-weight: 600;
  91. --f7-table-card-header-height: 42px;
  92. --f7-table-footer-height: 32px;
  93. --f7-table-footer-text-color: rgba(0, 0, 0, 0.5);
  94. --f7-table-input-text-color: #000;
  95. }
  96. .aurora .theme-dark,
  97. .aurora.theme-dark {
  98. --f7-table-selected-row-bg-color: rgba(255, 255, 255, 0.03);
  99. --f7-table-head-text-color: rgba(255, 255, 255, 0.52);
  100. --f7-table-footer-text-color: rgba(255, 255, 255, 0.52);
  101. }