【问题标题】:How to refresh datatable column data如何刷新数据表列数据
【发布时间】:2015-03-16 09:24:02
【问题描述】:

我使用带有表格作为数据源的数据表格插件。当用户在输入中输入一些数字时,我必须通过 javascript 更改一些列值(这个输入也是表格的一部分,我必须将这些值导出到)。它运行良好,但是当我想导出表格时,用 javascript 更改的列不会显示在导出的文件中。

我认为问题在于我没有刷新数据表插件。它是否正确?如果是,我该如何刷新数据源?如果没有,可能是什么问题,我该如何解决?

我尝试了refresh() 方法(var dataTableObject = $(this).parents('table').dataTable(); dataTableObject.refresh();)和$(this).parents('table').dataTable(),但都不起作用。

编辑:这是我如何更改单元格值:

$item.find('input.quantity-coefficient').each(function (i, d) {
        $(d).off('change').on('change', function () {
            var multiplier = $(this).val();
            //var dataTableObject = $(this).parents('table').dataTable();

            $($(this).data("row-price-info-class")).each(function (i, d) {
                var priceContainer = $(d);
                var price = parseFloat(priceContainer.data('price-value'));

                var priceInfoRatioContainer = $(priceContainer.data("ratio-input-class"));
                if (multiplier * price == 0) {
                    priceInfoRatioContainer.closest("td").addClass("no-euro");
                    priceInfoRatioContainer.html(" ");
                } else {
                    priceInfoRatioContainer.closest("td").removeClass("no-euro");
                    priceInfoRatioContainer.html(localizeNumber(multiplier * price));
                }

            });
            //TODO redrow the data 
            $(this).parents('table').dataTable().fnDraw();;
        });
    });

【问题讨论】:

    标签: javascript jquery datatable export


    【解决方案1】:

    您可以使用fnDraw() 刷新数据表。在您的示例中:

    $(this).parents('table').dataTable().fnDraw();
    

    【讨论】:

    • 感谢您的回复,但这不起作用。至少我的列数据不在导出的文件中:(
    • 我在原帖里加了
    【解决方案2】:

    谢谢你们,但我想我在这篇文章中找到了解决方案:jquery DataTables - change value of a cell not just display value

    当我第一次尝试时,问题是我从 1 而不是从 0 开始行编号。

    所以对于其他可能有这个问题的人,我必须使用这样的东西:

    (this).parents('table').dataTable().fnUpdate("new value", 0, 2)
    

    更新单元格值。其实这不是我问的,因为这不是刷新所有表格,但这是我现在的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      相关资源
      最近更新 更多