-
-
Save EugeneZheleznov/389f1a8af69ff0c7ea483219ba890de1 to your computer and use it in GitHub Desktop.
[CSV в HTML таблицу] #csv #jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.noConflict(); | |
(function ($) { | |
$.ajax({ | |
url: 'http://getdevs.ru/LoginAndPasswordWebCabinet.csv', | |
dataType: 'text', | |
}).done(successFunction); | |
function successFunction(data) { | |
var allRows = data.split(/\r?\n|\r/); | |
var table = '<table>'; | |
for (var singleRow = 0; singleRow < allRows.length; singleRow++) { | |
if (singleRow === 0) { | |
table += '<thead>'; | |
table += '<tr>'; | |
} else { | |
table += '<tr>'; | |
} | |
var rowCells = allRows[singleRow].split(','); | |
for (var rowCell = 0; rowCell < rowCells.length; rowCell++) { | |
if (singleRow === 0) { | |
table += '<th>'; | |
table += rowCells[rowCell]; | |
table += '</th>'; | |
} else { | |
table += '<td>'; | |
table += rowCells[rowCell]; | |
table += '</td>'; | |
} | |
} | |
if (singleRow === 0) { | |
table += '</tr>'; | |
table += '</thead>'; | |
table += '<tbody>'; | |
} else { | |
table += '</tr>'; | |
} | |
} | |
table += '</tbody>'; | |
table += '</table>'; | |
$('body').append(table); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment