JSFiddle - React, Tailwind, and code Playground
by Chris
HTML
<script src="https://editor-latest.s3.amazonaws.com/v3/js/froala_editor.pkgd.min.js"></script>
<link rel="stylesheet" href="https://editor-latest.s3.amazonaws.com/v3/css/froala_editor.pkgd.min.css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.20.0/dist/bootstrap-table.min.css">
<script src="https://unpkg.com/bootstrap-table@1.20.0/dist/bootstrap-table.min.js"></script>
<div id="froala-editor1"></div>
<table id="tabla_grafico" data-pagination="false" data-classes="table table-hover table-condensed" data-striped="false" style="width: 100%;"></table>
JavaScript
var graph_editor = new FroalaEditor('#froala-editor1', {
"toolbarButtons": ['undo', 'redo', '|', 'html'],
"placeholderText": 'Pegue su excel aquí',
"height": $(window).height() - 100,
"documentReady": false,
"events": {
//PASTE.AFTER RUNS ONLY AFTER WE PASTE SOMETHING INTO THE EDITOR
'paste.after': function () {
//var datos_tabla = $("#tabla_grafico").bootstrapTable('getData');
var html = graph_editor.el;
$("#isPasted").attr("id", "table_graph");
var tb = $('#table_graph:eq(0) tbody');
var size = tb.find("tr").length;
let anio = null;
let year = null;
let f = null;
let headers= [];
let rows = [];
tb.find("tr").each(function(index, element) {
var colSize = $(element).find('td').length;
//console.log(" Numero de columnas en una fila " + (index + 1) + " : " + colSize);
var fila = index + 1;
$(element).find('td').each(function(index, element) {
var colVal = $(element).text();
var columna = index + 1;
//console.log("Palabra " + (index + 1) + " : " + colVal.trim());
//ESTO RECORRE LAS FILAS DE AñOS
if (fila == 4 && columna == 1) {
anio = colVal.trim();
f = parseInt(anio);
}
//INSERTAMOS TITULO DE COLUMNAS
if (fila == 4 && columna >= 1) {
headers.push(parseInt(colVal.trim()));
}
//INSERTAMOS EL RESTO DE LOS DATOS
if (fila > 4) {
if(columna==1){
agrupacion = colVal.trim();
}
if (columna >= 2) {
year = f + columna - 2;
var valor = colVal.trim();
rows.push({"agrupacion": agrupacion, "valor": valor, "year": year});
year++;
}
}
//anio++;
});
});
editor =...