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

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

GridJs isn't sorting column when converting from HTML table

问题

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

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

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

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

const table = new gridjs.Grid({
  search: true,
  pagination: true,
  sort: true,
  resizable: true,
  from: document.getElementById('myTable'),
}).render(document.getElementById('destination'));

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

<script src="https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js"></script>
<link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet"/>

<div id='destination'></div>
<table id="myTable">
  <thead class="align-bottom">
    <tr>
      <th>Prénom</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <span>aaaa</span>
      </td>
    </tr>
    <tr>
      <td>
        <span>bbbb</span>
      </td>
    </tr>
    <tr>
      <td>
        <span>cccc</span>
      </td>
    </tr>
  </tbody>
</table>

<!-- 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 -->

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

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

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;https://unpkg.com/gridjs/dist/theme/mermaid.min.css&quot; rel=&quot;stylesheet&quot;/&gt;

&lt;div id=&#39;destination&#39;&gt;&lt;/div&gt;
    &lt;table id=&quot;myTable&quot;&gt;
        &lt;thead class=&quot;align-bottom&quot;&gt;
            &lt;tr&gt;
            
            &lt;th&gt;Pr&#233;nom&lt;/th&gt;
            
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;span&gt;aaaa&lt;/span&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;span&gt;bbbb&lt;/span&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
          &lt;tr&gt;
                &lt;td&gt;
                    &lt;span&gt;cccc&lt;/span&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
        &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 -->

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

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

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;https://unpkg.com/gridjs/dist/theme/mermaid.min.css&quot; rel=&quot;stylesheet&quot;/&gt;

&lt;div id=&#39;destination&#39;&gt;&lt;/div&gt;
    &lt;table id=&quot;myTable&quot;&gt;
        &lt;thead class=&quot;align-bottom&quot;&gt;
            &lt;tr&gt;
            
            &lt;th&gt;Pr&#233;nom&lt;/th&gt;
            
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    aaaa
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    bbbb
                &lt;/td&gt;
            &lt;/tr&gt;
          &lt;tr&gt;
                &lt;td&gt;
                    cccc
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
        &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:

确定