Seguí esta pregunta para crear una tabla -> tabla de Excel en HTML a través de Javascript
Mi tabla está conectada a un calendario creado a través de la biblioteca fullCalendar e implementé esta tabla en un modal. También encontré una manera de obtener el mes visualizado actual como encabezado de la tabla (usando getView). Pero ahora tengo este error: Así es como aparece mi tabla la primera vez que la abro (es la visualización correcta): normal
y así me sale cuando lo abro por segunda vez, también en otro mes: mal
Estos son los mods que le hice al código vinculado a la pregunta añadida al principio aquí:
function renderTable($targetTable, date, view, element ) { var view = $('#calendar').fullCalendar('getView'); var start = view.intervalStart._d; var end = view.intervalEnd.subtract(1, 'days'); alert(end); //prende mese e anno attualmente visualizzati e lo imposta come titolo del modal nell'HTML const months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"]; //calcola il numero dei giorni nel mese (30/31/28) let numberOfDaysInMonth = new Date(end).getDate(); // just get the last day //create the table header to display the month and date, and make is span all the days + the names column + the total column. let $tableHeader = $(`<tr><th colspan="${numberOfDaysInMonth+2}" style="text-align: center;">${months[start.getMonth()]} ${start.getFullYear()}</th></tr>`)encontré la solución
Básicamente, donde llamo a la función que crea mi tabla, agregué esto:
//table2 is the ID of my table var table = document.getElementById('table2'); //i check if the table is empty; if it is than I render the thead and tbody if (table.rows.length == 0){ var date = new Date(); renderTable($('#table2'), date); } //if not, before I delete whats inside and than I render it else if(table.rows.lenght != 0){ $("#table2 thead").empty(); $("#table2 tbody").empty(); var date = new Date(); renderTable($('#table2'), date); }