Banana.Document.Table

In questo articolo

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.

 

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");

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('Examples');
var archivedProducts = Banana.document.table('Products').list('Archive');

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

 

 

Questa documentazione è superata

La documentazione più completa e aggiornata è quella di Banana Contabilità Plus: Provalo subito

Condividi questo articolo: Twitter | Facebook | LinkedIn | Email