multi_head_table.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {% macro get_table(headers1, headers2, rows, table_height, table_width, lock_column_count) %}
  2. <div style="overflow: auto;height: {{table_height}};width:{{table_width}};float: left;">
  3. <table class="table table-striped table-bordered table-hover" style="border:1px solid gray;">
  4. <thead>
  5. <tr>
  6. {% set _left = 0 %}
  7. {% for item in headers1 %}
  8. {% set name = item[0] %}
  9. {% set data_type = item[1] %}
  10. {% set value = item[2] %}
  11. {% set width = item[3] %}
  12. <th
  13. style="line-height: 30px;border: 1px solid #ddd;padding: unset;vertical-align: middle;text-align: center;
  14. {% if width %} width: {{width}}px;{% endif %}
  15. {% if loop.index==1 %}z-index: 3;{% endif %}
  16. {% if lock_column_count and loop.index<=lock_column_count %}
  17. {% if loop.index>1 %}{% set _left = _left + headers1[(loop.index-2)][3] %}{% endif %}
  18. left:{{_left}}px;{% endif %}"
  19. {% if data_type== 1 %} rowspan="{{value}}" {% endif %}
  20. {% if data_type== 2 %} colspan="{{value}}" {% endif %}
  21. {% if loop.index<=lock_column_count %}class="row_and_column" {% endif %}
  22. >{{name}}
  23. </th>
  24. {% endfor %}
  25. </tr>
  26. <tr>
  27. {% for item in headers2 %}
  28. {% set name = item[0] %}
  29. <th style="top:31px;line-height: 30px;border: 1px solid #ddd;padding: unset;vertical-align: middle;text-align: center;">
  30. {{name}}
  31. </th>
  32. {% endfor %}
  33. </tr>
  34. </thead>
  35. <tbody>
  36. {% for row in rows %}
  37. <tr>
  38. {% set _left = 0 %}
  39. {% for item in row %}
  40. <td
  41. {% if lock_column_count and loop.index<=lock_column_count %}
  42. {% if loop.index>1 %}{% set _left = _left + headers1[(loop.index-2)][3] %}{% endif %}
  43. style="left:{{_left}}px;background-color:
  44. lightpink;z-index: 1;position: sticky;{{item[1]}}"
  45. {% endif %}
  46. {% if item[2] %} {{item[2]}} {% endif %}
  47. >{{item[0]}}
  48. </td>
  49. {% endfor %}
  50. </tr>
  51. {% endfor %}
  52. </tbody>
  53. </table>
  54. </div>
  55. {% endmacro %}