In dit artikel
Banana.Document.Table is the interface of a table.
When using table it must always be a valid nameXml of a table.
To view the nameXml of a table: menu Data > Table Setup.
var table = Banana.document.table("Accounts"); // 'Accounts' is the nameXml of the table Accounts
When using columnName it must always be a valid nameXml of a column.
To view the nameXml of a column: menu Data > Column Setup > Settings.
var table = Banana.document.table("Accounts");
var account = table.value(3,'Account'); // 'Account' is the nameXml of the column account of Accounts table
Properties
name
Return the xml name of the table.
var table = Banana.document.table("Accounts");
var tName = table.name;
columnNames
Return the xml names of the table's columns as an array of strings.
var table = Banana.document.table("Accounts");
var tColumnNames = table.columnNames;
The columns vary depending on the table and accounting type. For example in the Transactions table of a multi-currency accounting with VAT these are the columns:
SysCod, Section, Date, DateDocument, DateValue, Doc, DocProtocol, DocType, DocOriginal, DocInvoice, InvoicePrinted, DocLink, ExternalReference, ItemsId, Description, Notes, AccountDebit, AccountDebitDes, AccountCredit, AccountCreditDes, Quantity, ReferenceUnit, UnitPrice, AmountCurrency, ExchangeCurrency, ExchangeRate, ExchangeMultiplier, Amount, Balance, VatCode, VatAmountType, VatExtraInfo, VatRate, VatRateEffective, VatTaxable, VatAmount, VatAccount, VatAccountDes, VatPercentNonDeductible, VatNonDeductible, VatPosted, VatNumber, Cc1, Cc1Des, Cc2, Cc2Des, Cc3, Cc3Des, Segment, DateExpiration, DateExpected, DatePayment, LockNumber, LockAmount, LockProgressive, LockLine
listName
Return the xml name of the list that this table object references to. The default list is the 'Data' list.
var table = Banana.document.table("Accounts");
var tListName = table.listName;
listNames
Return the xml names of the available lists as an array. The default list is the 'Data' list.
var table = Banana.document.table("Accounts");
var tListNames = table.listNames;
rowCount
Return the number of rows in the table.
var table = Banana.document.table("Accounts");
var tRowCount = table.rowCount;
rows
Return the rows of the table as an array of Row objects.
var table = Banana.document.table("Accounts");
var tRows = table.rows;
Note: In a loop use the method table.row(rowNr) instead of table.rows[rowNr]. The property rows can be very expensive with large tables and slow down or block the execution of the script.
viewNames
Return the xml names of the available views as an array.
var table = Banana.document.table("Accounts");
var tViewNames = table.viewNames;
This property was introduced in BananaPlus 10.0.12.088.
Methods
addMessage(msg, rowNr [, columnName] [, idMsg])
Add the message msg to the queue of the document. The message is showed in the pane "Messages", and in a dialog if the application option "Show Messages" is turned on.
If idMsg is not empty, the help button calls an url with message's id (idMsg) as parameter.
If rowNr is different than "-1" the message is connected to the row rowNr. if columnName is not empty, the message is connected to the column columnName. With a double click over message in the message pane, the cursor jump to the corresponding table, rowNr and columnName.
See also: Application.AddMessage, Row.AddMessage, Document.AddMessage.
var table = Banana.document.table("Accounts");
table.addMessage("Message string", 3, "description");
column(columnName [, viewName])
Return the Column with the given name in the given view as Column Object.
The viewName is optional, if not defined the view number 1 (usually the "Base" view) or if not present the first view in the list is taken.
The column's informations are dependent of the view, therefore the same column can have for example different headers depending on the given view.
var tColumn = Banana.document.table("Transactions").column("Description", "Base");
var colHeader = tColumn.header;
This method was introduced in BananaPlus 10.0.12.088.
extractRows( function(rowObj, rowNr, table), tableTitle)
Return an array of rows filled with all row elements that pass a test (provided as a function) and show them in the table "Selections".
The title of the table is set to tableTitle.
function accountStartsWith201(rowObj,rowNr,table) {
// Return true if account start with '201'
return rowObj.value('Account').startsWith('201');
}
var tableAccount = Banana.document.table('Accounts');
// Show a table with all accounts that start with '201'
tableAccount.extractRows(accountStartsWith201, 'Accounts that start with 201');
findRows( function(rowObj, rowNr, table))
Return an array of Row objects that pass a test (provided as a function).
function accountStartsWith201(rowObj,rowNr,table) {
// Return true if account start with '201'
return rowObj.value('Account').startsWith('201');
}
var tableAccount = Banana.document.table('Accounts');
// Find rows of all accounts that start with '201'
var rows = tableAccount.findRows(accountStartsWith201);
findRowByValue(columnName, value)
Return the first row as Row object that contains the value in the the column columnName. Or undefined if any row is found.
var cashAccountRow = Banana.document.table('Accounts').findRowByValue('Account','1000');
if (!cashAccountRow)
//Row not found
list(xmlListName)
Return a new table object with the rows of the list xmlListName, or undefined if the list xmlListName doesn't exist.
var recurringTransactions = Banana.document.table('Transactions').list('Recurring');
var archivedProducts = Banana.document.table('Products').list('Archive');
progressiveNumber(columnName [, includeArchive])
Return the progressive number for the column columnName. If includeArchive is true, the Archive table is also take into account.
As API Version 1.2.2 or BananaPlus Version 10.0.13.240 this method works also with alphanumeric ("DOC-021") and composite ("2022-021") numbers. For example, if the last used number is "DOC-021" this method returns "DOC-022", if the the last used number is "2022-021" this method returns "2022-022".
var trasactionsTable = Banana.document.table("Transactions");
var nextDocNr = trasactionsTable.progressiveNumber("Doc");
var invoicesTable = Banana.document.table("Invoices", true);
var nextInvoiceNr = invoicesTable.progressiveNumber("Id", true);
row(rowNr)
Return the Row at index rowNr as Row Object, or undefined if rowNr is outside the valid range.
var table = Banana.document.table("Accounts");
var row = table.row(3);
toJSON([columnNames])
Return the table data content as JSON string. If the parameter columnNames is defined, only the columns in the array are included in the file.
var table = Banana.document.table("Accounts");
var json = table.toJSON();
toHtml([columnNames, formatValues])
Return the table data content as Html file. If the parameter columnNames is defined, only the columns in the array are included in the file. If formatValues is set to true, the values are converted to the locale format.
Example:
//Show the whole row content of the table Accounts
Banana.Ui.showText(Banana.document.table('Accounts').toHtml());
//Show some columns and format dates, amounts, ... as displayed in the program
Banana.Ui.showText(
Banana.document.table('Accounts').toHtml(['Account','Group','Description','Balance'],true)
);
toTsv([columnNames])
Return the table as Tsv file (Tab separated values). If the parameter columnNames is defined, only the columns in the array are included in the file.
var table = Banana.document.table("Accounts");
var tsv = table.toTsv();
value(rowNr, columnName)
Return the value in row rowNr and column columnName as string. Or undefined if the row or column are not found.
var table = Banana.document.table("Accounts");
var account = table.value(3,'Account');
var description = table.value(3,'Description');