Banana.Document.Table

文件资料 •
在此文中

Banana.Document.Table is the interface of a 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.


var table = Banana.document.table("Accounts");
var tColumnNames = table.columnNames;

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.AddMessageRow.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');

请帮助我们完善必备文件

我们非常欢迎您发送宝贵的反馈意见

请告诉我们什么主题需要更好的解释或如何才能更好的对其诠释。

分享这篇文章: Twitter | Facebook | LinkedIn | Email