Search code examples
jquerytablesorter

jQuery Tablesorter - exports dates instead of floats


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     : ';'}
    });
});

Solution

  • 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/