GridJs 在从 HTML 表格转换时没有对列进行排序。

huangapple go评论113阅读模式
英文:

GridJs isn't sorting column when converting from HTML table

问题

我正在尝试使用GridJS来对现有的HTML表格进行排序和搜索。
但是排序功能不起作用。搜索栏正常。

有任何想法吗?我认为这应该很简单,但我卡在那里。

  1. <!-- begin snippet: js hide: false console: true babel: false -->
  2. <!-- language: lang-js -->
  3. const table = new gridjs.Grid({
  4. search: true,
  5. pagination: true,
  6. sort: true,
  7. resizable: true,
  8. from: document.getElementById('myTable'),
  9. }).render(document.getElementById('destination'));
  10. <!-- language: lang-html -->
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js"></script>
  12. <link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet"/>
  13. <div id='destination'></div>
  14. <table id="myTable">
  15. <thead class="align-bottom">
  16. <tr>
  17. <th>Prénom</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. <tr>
  22. <td>
  23. <span>aaaa</span>
  24. </td>
  25. </tr>
  26. <tr>
  27. <td>
  28. <span>bbbb</span>
  29. </td>
  30. </tr>
  31. <tr>
  32. <td>
  33. <span>cccc</span>
  34. </td>
  35. </tr>
  36. </tbody>
  37. </table>
  38. <!-- end snippet -->

希望这有助于解决您的问题。如果还有其他问题,请随时提出。

英文:

I'm trying to use GridJS to sort/search an existing html table.
But sorting isn't working. The search bar is ok.

Any idea ? I think it should be easy but i stuck there

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. const table = new gridjs.Grid({
  2. search: true,
  3. pagination: true,
  4. sort: true,
  5. resizable: true,
  6. from: document.getElementById(&#39;myTable&#39;),
  7. }).render(document.getElementById(&#39;destination&#39;));

<!-- language: lang-html -->

  1. &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js&quot;&gt;&lt;/script&gt;
  2. &lt;link href=&quot;https://unpkg.com/gridjs/dist/theme/mermaid.min.css&quot; rel=&quot;stylesheet&quot;/&gt;
  3. &lt;div id=&#39;destination&#39;&gt;&lt;/div&gt;
  4. &lt;table id=&quot;myTable&quot;&gt;
  5. &lt;thead class=&quot;align-bottom&quot;&gt;
  6. &lt;tr&gt;
  7. &lt;th&gt;Pr&#233;nom&lt;/th&gt;
  8. &lt;/tr&gt;
  9. &lt;/thead&gt;
  10. &lt;tbody&gt;
  11. &lt;tr&gt;
  12. &lt;td&gt;
  13. &lt;span&gt;aaaa&lt;/span&gt;
  14. &lt;/td&gt;
  15. &lt;/tr&gt;
  16. &lt;tr&gt;
  17. &lt;td&gt;
  18. &lt;span&gt;bbbb&lt;/span&gt;
  19. &lt;/td&gt;
  20. &lt;/tr&gt;
  21. &lt;tr&gt;
  22. &lt;td&gt;
  23. &lt;span&gt;cccc&lt;/span&gt;
  24. &lt;/td&gt;
  25. &lt;/tr&gt;
  26. &lt;/tbody&gt;
  27. &lt;/table&gt;

<!-- end snippet -->

答案1

得分: 0

我发现问题是范围。我刚刚把它移除了。

英文:

I found, the problem was the span. I just removed it.

<!-- begin snippet: js hide: false console: true babel: null -->

<!-- language: lang-js -->

  1. const table = new gridjs.Grid({
  2. search: true,
  3. pagination: true,
  4. sort: true,
  5. resizable: true,
  6. from: document.getElementById(&#39;myTable&#39;),
  7. }).render(document.getElementById(&#39;destination&#39;));

<!-- language: lang-html -->

  1. &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js&quot;&gt;&lt;/script&gt;
  2. &lt;link href=&quot;https://unpkg.com/gridjs/dist/theme/mermaid.min.css&quot; rel=&quot;stylesheet&quot;/&gt;
  3. &lt;div id=&#39;destination&#39;&gt;&lt;/div&gt;
  4. &lt;table id=&quot;myTable&quot;&gt;
  5. &lt;thead class=&quot;align-bottom&quot;&gt;
  6. &lt;tr&gt;
  7. &lt;th&gt;Pr&#233;nom&lt;/th&gt;
  8. &lt;/tr&gt;
  9. &lt;/thead&gt;
  10. &lt;tbody&gt;
  11. &lt;tr&gt;
  12. &lt;td&gt;
  13. aaaa
  14. &lt;/td&gt;
  15. &lt;/tr&gt;
  16. &lt;tr&gt;
  17. &lt;td&gt;
  18. bbbb
  19. &lt;/td&gt;
  20. &lt;/tr&gt;
  21. &lt;tr&gt;
  22. &lt;td&gt;
  23. cccc
  24. &lt;/td&gt;
  25. &lt;/tr&gt;
  26. &lt;/tbody&gt;
  27. &lt;/table&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月29日 19:51:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580772.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定