Advertisement
Guest User

Untitled

a guest
May 30th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  *  @name                           table2csv
  3.  *  @descripton                     Converts an html table to CSV
  4.  *  @version                        0.1
  5.  *  @requires                       jQuery
  6.  *
  7.  *  @author                         John Ballantyne
  8.  *  @author-email                   johnballantyne@gmail.com
  9.  *
  10.  *  @licence                        MIT License - http://www.opensource.org/licenses/mit-license.php
  11.  */
  12. (function( $ ) {
  13.     $.fn.table2csv = function(selector) {
  14.  
  15.         var output = ""
  16.  
  17.         $(selector).each(function() {
  18.             var $rows = $(this);
  19.             var $ele = $rows.children();
  20.             $ele.each(function() {
  21.                 var cell = $(this).html().replace(/\$|,/g, "");
  22.                // cell = cell.replace(/$/g, "");
  23.  
  24.                 output += cell + ",";
  25.             });
  26.             output += ";";
  27.  
  28.         });
  29.  
  30.         output = output.replace(/,;/g, ";");
  31.         return output;
  32.     };
  33. })( jQuery );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement