Export child table
I might be wrong but there doesn't seem a native way how to export records in a child table. Seems the best option atm is to use the ninext from Jacques TUR https://forum.ninox.com/t/x2hbnct/using-a-button-to-export-multiple-records#y4hst7p .
Or?
13 replies
-
What do you mean by "exporting records to a child table"?
- Copy records to the same database?
- Copy records to another database?
-
Do you mean you want to export a child table from the parent?
You can always just go to the actual table and export the data.
-
Oh sorry yes. Exporting to like excel or csv :).
Happy new year and thank you so much for being so supportive <3. -
Jacques TUR I am trying to implement the export button using ninext as you described in the post, I posted:
var fileName := "myExport2.csv"; var exportSettings := { sep: ",", qut: """", lf: "%0D%0A", numberFormat: "point", dateFormat: "locale", header: true, sepHeader: false, encoding: "utf8" } var data := #{:text:callback window.util.renderCSV(window.database, window.ui.currentView.table, exportSettings) .then((textData) => { callback(textData); }) }#; createTextFile( this, data, fileName );
But it looks like the new line separator is wrong as I get the complete result in one line without new lines.
I added a debugger but I struggle to find out how I can reverse engineer window.util.renderCSV(...) . How you do it normally :) ? -
Jacques TUR nice that works :). Can you tell me how did you know about urlDecode(...) and the other functions likes renderCSV(...) ? Is it part of nativeJS ?
-
And it is a bit more tricky in my case because, I do ask for exporting the child table to csv and not the `window.ui.currentView.table` . So what I try is to grab that element without success so far:
var fileName := Kunde.Firma + "-" + Kunde.Standort + "-Stueckliste.csv"; var exportSettings := { sep: ",", qut: """", lf: urlDecode("%0D%0A"), numberFormat: "point", dateFormat: "locale", header: true, sepHeader: false, encoding: "utf8" }; #{:text:callback debugger; //var table = window.ui.currentView.table; // find the tab bar of top level form. var components = (widgets.popupEditorStack.length > 0 ? widgets.popupEditorStack[widgets.popupEditorStack.length - 1] : ui.sideEditor && ui.sideEditor).editor.currentTab.components; // console.log(components); var table = components && components.find( c => c.field.caption == "ProjektStueckliste" ); var realTable; if (table) { // table.$headCells[numCol].innerText = newColTitle // table.$["nx-table__head__cell"][numCol].innerText = newColTitle let list = table.list[0]; realTable = table.list[0].firstChild; } window.util.renderCSV(window.database, realTable, exportSettings) .then((textData) => { NinoxDocumentInteraction.openFileWithServer(fileName, 'text/csv', textData, !1, !0) callback(textData) }) }#
So I guess what I am trying here is quite tricky. I don't think, I can use renderCSV(...) for popups.
-
You have several solutions:
1 : Automatically open the table you want to export using ui.openTable
var tableName := "Invoice"; var tabName := "All Invoices"; var fileName := "myExport2.csv"; var exportSettings := { sep: ",", qut: """", lf: "%0D%0A", numberFormat: "point", dateFormat: "locale", header: true, sepHeader: false, encoding: "utf8" } var data := #{:text:callback //save current view display var ns = ui.currentView.getNavigationState(); // retrieve type Id from tableName var tid = database.schema.findType(tableName) && database.schema.findType(tableName).id; // retrieve view from type Id and tab Id var view = tid && Object.values(database.views).find(v => { return v.type == tid && v.caption == tabName }) //Open table with specifique tab if (view) { ui.openTable(tid, view.id); window.util.renderCSV(window.database, window.ui.currentView.table, exportSettings) .then((textData) => { callback(textData); }) } else callback(`view ${tableName}:${tabName} not found !`) //re open previous view ui.openTable(ns.tid, ns.vid); }#; createTextFile( this, data, fileName );
2 : Simulate the display of a table and export the object thus constructed
var fileName := "myExport2.csv"; var tableName := "Customer"; var tabName := "All customers"; var exportSettings := { sep: ",", qut: """", lf: "%0D%0A", numberFormat: "point", dateFormat: "locale", header: true, sepHeader: false, encoding: "utf8" } var data := #{:text:callback debugger; // duplicate table object from ui.views.table.table var table = Object.assign({}, ui.views.table.table, Object.getPrototypeOf(ui.views.table.table)) // var table = Object.assign({}, ui.currentView.table, Object.getPrototypeOf(ui.currentView.table)) // clear display function table.createCells = () => { }; table.updateRows = () => {}; table.updateHead = () => {}; table.updateFoot = () => {}; table.retainSelection = () => {}; // retrieve type Id from tableName var tid = database.schema.findType(tableName) && database.schema.findType(tableName).id; // retrieve view from type Id and tab Id var view = tid && Object.values(database.views).find(v => { return v.type == tid && v.caption == tabName }) if (view) { // initialize the table table.setConfig(view.config, {}); // load the rows table.load(() => { //render CSV; util.renderCSV(database, table, exportSettings) .then((textData) => { callback(textData); }) }) } else callback(`view ${tableName}:${tabName} not found !`) }#; createTextFile( this, data, fileName );
3 : Build the string yourself by compiling all the fields you want to appear in your file. This may be the simplest solution in the end, right?
-
Thanks Jacques TUR you are amazing !!!
The ui.openTable suggestion from you gave me a nice idea where I allow to open the child table view (which is normally hidden) by setting the filter to filter project-specific rows. Then the user can use the native export mechanism which is great :).
var tableName := "ProjektStueckliste"; var tabName := "Projekt"; var projektNummer := Projektnummer; var firma := Kunde.Firma; var standort := Kunde.Standort; #{:text:callback debugger; //save current view display var ns = ui.currentView.getNavigationState(); // retrieve type Id from tableName var tid = database.schema.findType(tableName) && database.schema.findType(tableName).id; // retrieve view from type Id and tab Id var view = tid && Object.values(database.views).find(v => { return v.type == tid && v.caption == tabName }) //Open table with specifique tab if (view) { view.config.cols[6].filter = firma; view.config.cols[7].filter = standort; view.config.cols[8].filter = projektNummer; ui.openTable(tid, view.id); } else callback(`view ${tableName}:${tabName} not found !`) }#
I have just one last problem. After I click the button the spinner doesn't stop and the side isn't available anymore. Though the table view is loaded correctly :).
-
I removed the callbacks. That solved it. Thanks a lot :)!
Content aside
- Status Answered
-
1
Likes
- 1 yr agoLast active
- 13Replies
- 229Views
-
3
Following