【问题标题】:Datatable not displaying all table columns数据表不显示所有表列
【发布时间】:2015-12-15 22:20:00
【问题描述】:

我对 DataTable 库有一个非常奇怪的行为。

我有一个包含 14 个元素的循环的经典表格。正常显示时,一切都会出现,当我将其设为 DataTable 时,最后 4 列消失。

我的代码中,horizo​​n 的值为 14(已测试),并且只显示 10 列循环(如果我删除 DataTable 类,则显示所有内容):

<table id="ingredients_table" class="table DataTable">
    <thead>
        <tr>
            <th>Produit</th>
            <th>Marque</th>
            <th title="Quantité disponible dans un produit" data-toggle="tooltip" data-placement="top">Packaging</th>
            <th title="Unité de gestion des stocks" data-toggle="tooltip" data-placement="top">UGS</th>
            <th>Stock min</th>
            <th>Stock actuel</th>
            <th class="text-right">J+</th>
            {% for i in 1..horizon %}
                <th>{{ i }}</th>
            {% endfor %}
        </tr>
    </thead>
    <tbody>
    {% spaceless %}
        {% for ingredient in ingredients -%}
            <tr data-table_form_id="{{ ingredient.id }}" data-id="{{ ingredient.id }}" data-repo="AppBundle:FoodAnalytics\UserIngredient">
                <td>{{ ingredient.getInferredName }}</td>
                <td>{{ ingredient.getProductBrand }}</td>
                <td>{{ ingredient.getProductPackaging }}</td>
                <td style="min-width: 100px !important;" data-table_form_value="{{ ingredient.unit.id }}">
                    {{ ingredient.unit }}
                </td>
                <td style="min-width: 70px !important;">
                    {{ ingredient.stockMini | round_quantity }}
                </td>
                <td style="min-width: 70px !important;">
                    {{ ingredient.getLastNumberObjectValue() }}
                </td>
                <td><span class="sparkline" data-id="{{ ingredient.id }}"></span></td>
                {% for i in 1..horizon %}
                    {% if stocks[ingredient.id][i] < 0 %}
                        {% set class = 'text-danger' %}
                    {% elseif stocks[ingredient.id][i] < ingredient.stockMini %}
                        {% set class = 'text-warning' %}
                    {% endif %}
                    <td{% if class is defined %} class="{{ class }}"{% endif %}>
                        {{ stocks[ingredient.id][i]|round_quantity }}
                    </td>
                {% endfor %}
            </tr>
        {% endfor %}
    {% endspaceless %}
    </tbody>
    <tfoot>
    <tr>
        <th>Produit</th>
        <th>Marque</th>
        <th title="Quantité disponible dans un produit" data-toggle="tooltip" data-placement="top">Packaging</th>
        <th title="Unité de gestion des stocks" data-toggle="tooltip" data-placement="top">UGS</th>
        <th>Stock min</th>
        <th>Stock actuel</th>
        <th class="text-right">J+</th>
        {% for i in 1..horizon %}
            <th>{{ i }}</th>
        {% endfor %}
    </tr>
    </tfoot>
</table>

$('.DataTable').DataTable({iDisplayLength: 50, responsive: true});

有人知道出了什么问题吗?

【问题讨论】:

  • ok,找到了,来自dataTable初始化的响应选项。为什么这样做?这不是预期的。

标签: html twitter-bootstrap datatable twig html-table


【解决方案1】:

试试这个:

$(document).ready(function(){
$('.DataTable').DataTable({iDisplayLength: 50, responsive: true});
});

【讨论】:

  • 我的 js 行是一个代码 sn-p,已经在一个文档就绪函数中。我必须删除响应选项才能使其工作
猜你喜欢
  • 2017-06-02
  • 1970-01-01
  • 2020-10-23
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2015-08-21
  • 2012-08-12
  • 2016-02-22
相关资源
最近更新 更多