Skip to content

Commit

Permalink
Added CSV format to be exported into. It places the field names on th…
Browse files Browse the repository at this point in the history
…e first line as header and the data follows.

all fields are surrounded with " "
all fields are seperated with ,
  • Loading branch information
dominionit committed Dec 3, 2014
1 parent 752d73c commit 907eaae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions index.html
Expand Up @@ -114,6 +114,11 @@ <h5>Select type:</h5>
<input type="radio" class="codetype" name="codetype" id="jsontype" value="jsontype">
JSON
</label>
<label class="radio">
<input type="radio" class="codetype" name="codetype" id="csvtype" value="csvtype">
CSV
</label>

<p>
<button id="getcode" class="btn btn-primary" type="button">Get it!</button>
</p>
Expand Down
26 changes: 23 additions & 3 deletions js/functions.js
Expand Up @@ -103,6 +103,7 @@ $(document).ready(function () {
var sql = "";
var xml = "";
var json = "";
var csv = "";

if (settings.type === "mysqltype") {
// create table
Expand Down Expand Up @@ -212,11 +213,30 @@ $(document).ready(function () {
}
sql = sql.substring(0, sql.length - 2);
sql += "); \n"
}
}
sql = sql.substring(0, sql.length - 1);

// set sql code
$('#generatedcode').text(sql);
}
}
} else if (settings.type === "csvtype") {
csv = "";
for (var j = 0; j < oLength; j++) {
var currOption = options[j];
csv += "\"" + currOption + "\",";
}
csv = csv.substring(0, csv.length - 1);
csv += "\n";
for (var i = 0; i < valuesLength; i++) {
for (var j = 0; j < oLength; j++) {
var currValue = allValues[i][options[j]];
csv += "\"" + currValue + "\",";
}
csv = csv.substring(0, csv.length - 1);
csv += "\n";
}

// set csv code
$('#generatedcode').text(csv);
}
}
});

0 comments on commit 907eaae

Please sign in to comment.