【问题标题】:Showing the index of a row in a bootstrap table在引导表中显示行的索引
【发布时间】:2016-02-22 09:08:56
【问题描述】:

我希望能够在引导表中显示相应行的索引。我的表格如下所示:

<div class="Explorer" style="display:none">
<table class='table'>
    <thead>
        <tr>
            <th>Rank</th>
            <th>Username</th>
            <th>Points</th>
        </tr>
    </thead>
{% for instance in leaderboardDictionaries %}
    {% for category, userDictionary in instance.items %}
        {% if category == "Explorer" %}
            <tr><td> {{category}} </td></tr>
            {% for name, points in userDictionary.items %}
                <tr>
                    <td data-formatter="runningFormatter" data-field="index">HERE I WANT THE INDEX OF THE ROW?!</td>
                    <td>{{name}}</td>
                    <td>{{points}}</td>
                </tr>
            {% endfor %}
        {% endif %}
    {% endfor %}
{% endfor %}
</table>
</div>

我在网上查看并找到了这个,但我无法让它以任何有用的方式工作......所以建议是制作一个外部函数:

<script>
function runningFormatter(value, row, index) {
return index+1;
}
</script>

但是我应该如何使用它?该函数已经将行和索引作为参数。而且我想知道为什么表格没有“格式选项”,这样我就默认显示行索引 --- 还是有?

【问题讨论】:

    标签: html bootstrap-table


    【解决方案1】:

    您需要将data- 属性放在&lt;th&gt; 元素中,而不是&lt;td&gt; 元素中,因为它们是列级属性。

    &lt;th data-formatter="runningFormatter"&gt;Rank&lt;/th&gt;

    其次,data-field 用于将数据从 javascript 数组或外部源映射到您的列。您不需要那个,因为您是用 html 编写表格。

    index 将根据显示的数据返回行索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 2016-07-31
      • 2010-09-22
      • 2017-02-07
      相关资源
      最近更新 更多