jQuery Tablesorter - exports dates instead of floats

非 Y 不嫁゛ 提交于 2019-12-13 00:03:24

问题


DEMO

When i export my table to csv the floats are separated with decimal dot "." and in excel the values are converted to dates instead of keeping them like they are in HTML table.

Is there a way to replace the dots with decimal comma ","

$(function () {

    var $table = $('table');

    $('.download').click(function(){
        $table.trigger('outputTable');
    });

    $table.tablesorter({
        theme: 'blue',
        widgets: ['zebra', 'output'],
        widgetOptions : { output_delivery : 'd', output_separator     : ';'}
    });
});

回答1:


You can config a output_formatContent, like this:

$(function() {
  var $table = $('table');

  $('.download').click(function() {
    $table.trigger('outputTable');
  });

  $table.tablesorter({
    theme: 'blue',
    widgets: ['zebra', 'output'],
    widgetOptions: {
      output_delivery: 'd',
      output_separator: ';',
      output_formatContent: function(c, wo, data) {
        if (c.parsers[data.$cell['0'].cellIndex].type !== 'numeric')
          return data.content;
        return data.content.replace(/\./ig, ',');
      }
    }
  });
});

You can check here: http://jsfiddle.net/abkNM/8781/



来源:https://stackoverflow.com/questions/40787656/jquery-tablesorter-exports-dates-instead-of-floats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!