/** * A view that contains and displays data. * Provides functions to convert the data to CSV for exports. * To be enhanced by more table-related functions in the future. */ class DataTable extends View { /** * Builds a cell. The default is just a normal text cell. * May be overridden to implement other kinds of cells, like checkboxes. */ buildCell() { } /** * Returns the effective data that is displayed in the view. * By default, this just returns the raw data, but the function may be overriden to change this behaviour. */ getDisplayTableData() { return this.data; } /** * Returns a CSV string with the table's data. */ getCSVData() { var data = this.getDisplayTableData(); if (!data || data.length == 0) { return ""; } var csvString = ""; for (var i = 0; i < data.length; i++) { var rowData = data[i]; var rowString = ""; for (var j = 0; j < rowData.length; j++) { var cell = "" + rowData[j]; if (cell.indexOf(",") != -1) { if (cell.indexOf("\"") != -1) { cell = cell.replaceAll("\"", "\"\""); } cell = "\"" + cell + "\""; } if (j > 0) { rowString += ","; } rowString += cell; } if (i > 0) { csvString += "\r\n"; } csvString += rowString; } return csvString; } }