Skip to content

Commit 20f28f0

Browse files
add create table with column headers from table schema fields prior to loading first page of data setup (#15)
1 parent c5c0e04 commit 20f28f0

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/views/tableView.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ export class TableView {
230230
console.log('tabular.data.view:tableSchema: columns:', this._tableSchema.fields);
231231
statusBar.showColumns(this._tableSchema.fields);
232232

233+
// create table in table view before loading data
234+
/*
235+
this.webviewPanel.webview.postMessage({
236+
command: 'createTable',
237+
tableSchema: this._tableSchema
238+
}); */
239+
233240
// create readable CSV data file stream
234241
const startReadTime: Date = new Date();
235242
const dataFileStream: fs.ReadStream =

web/scripts/tableView.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ window.addEventListener('resize', function () {
9696
// add data/config update handler
9797
window.addEventListener('message', event => {
9898
switch (event.data.command) {
99+
case 'createTable':
100+
createTable(event.data.tableSchema);
101+
break;
99102
case 'refresh':
100103
documentUrl = event.data.documentUrl;
101104
fileName = event.data.fileName;
@@ -171,7 +174,7 @@ function loadData(tableData, tableSchema) {
171174
logTableData(tableData);
172175
if (table === undefined) {
173176
// create table and load initial set of data rows
174-
createTable(tableData, tableSchema);
177+
table = createTable(tableSchema, tableData);
175178
}
176179
else {
177180
// add new data rows to existing tabulator table
@@ -183,11 +186,14 @@ function loadData(tableData, tableSchema) {
183186
/**
184187
* Creates new Tabulator table with initial set of data to display.
185188
*
186-
* @param {*} tableData Data array to display in tabulator table.
187189
* @param {*} tableSchema Data table schema with inferred column fields info.
190+
* @param {*} tableData Data array to display in tabulator table.
188191
*/
189-
function createTable(tableData, tableSchema) {
192+
function createTable(tableSchema, tableData) {
190193
if (table === undefined) {
194+
// show progress ring
195+
progressRing.style.visibility = 'visible';
196+
191197
// create table columns array from table schema fields
192198
tableColumns = createTableColumns(tableSchema);
193199
if (tableColumns.length > 0) {
@@ -207,6 +213,7 @@ function createTable(tableData, tableSchema) {
207213
console.log('tableView.table.dataLoaded():loadedData:', data.length.toLocaleString());
208214
});
209215
}
216+
return table;
210217
}
211218

212219
/**
@@ -221,7 +228,7 @@ function createTableColumns(tableSchema) {
221228
// Note: sometimes table rows are not parsed correctly
222229
// by the frictionless table schema infer() and returns only 1 field
223230
if (tableSchema && tableSchema.fields && tableSchema.fields.length > 1) {
224-
console.log('tableView.createTableColumns():tableSchema:', tableSchema.fields);
231+
// console.log('tableView.createTableColumns():tableSchema:', tableSchema.fields);
225232
tableSchema.fields.forEach(field => {
226233
// determine field sorter type
227234
let sorter = 'string';
@@ -243,8 +250,8 @@ function createTableColumns(tableSchema) {
243250
});
244251
});
245252
console.log('tableView.createTableColumns():columns:', tableColumns);
246-
return tableColumns;
247253
}
254+
return tableColumns;
248255
}
249256

250257
/**

0 commit comments

Comments
 (0)