# DataStore

# Classes

DataStore

Javascript DataStore implementation, it is similar to powerbuilder's DataStore.

# Functions

deepClone(source)Object

This is just a simple version of deep copy Has a lot of edge cases bug If you want to use a perfect deep copy, use lodash's _.cloneDeep

# DataStore

Javascript DataStore implementation, it is similar to powerbuilder's DataStore.

Kind: global class

# dataStore.dataObject

Kind: instance property of DataStore
Properties

Name Description
set data of the DataStore.

Example

let value = {
    units:0,
    processing:1,
    table:{
		retrieve:'select id,name,dt,price,des,num,bit from test1 order by id',
		update:'test1',
		updatewhere:2,
		updatekeyinplace:true,
		columns:[
			{name:'id',dbname:'id',type:'long',key:yes,update:true}
			{name:"name",dbname:'name',type:"string",update:true},
			{name:"age",type:"long",update:true},
			{name:"dt",type:"datetime",update:true},
			{name:'sex',type:"long",values:[{value:1,text:'男'},{value:0,text:'女'}]}
		],
	}
}
ds1.dataObject = value;

# dataStore.rowCount() ⇒ Number

Obtains the number of rows that are currently available in the primary buffer.

Kind: instance method of DataStore
Returns: Number - Long. Returns the number of rows that are currently available, 0 if no rows are currently available, and -1 if an error occurs.

# dataStore.setItem(row, column, value) ⇒ Number

SetItem sets a value in a DataWindow buffer.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs.

Param Type Description
row Number The row location of the data.
column String/Number/Object The column location of the data. Column can be a column number or a column name.
value String/Number The value to which you want to set the data at the row and column location.

Example

dw1.setItem(1,'name','Jake')

# dataStore.getItem(row, column) ⇒ Object

Gets the value of an item for the specified row and column. GetItem returns the value available in the data available to the client. This is equivalent to the primary buffer in other environments.

Kind: instance method of DataStore
Returns: Object - Returns the value in the specified row and column. The data type of the returned data corresponds to the data type of the column. Returns the empty string ("") if an error occurs.

Param Type Description
row Number A value identifying the row location of the data..
column String/Number The column location of the data. Column can be a column number or a column name.

# dataStore.setItemStatus(row, column, dwbuffer, status) ⇒ Number/NULL

Changes the modification status of a row or a column within a row. The modification status determines the type of SQL statement the Update method will generate for the row.

Kind: instance method of DataStore
Returns: Number/NULL - Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is NULL, in PowerBuilder and JavaScript the method returns NULL.

Param Type Description
row Number A value identifying the row location of the data..
column String/Number The column location in which you want to set the status. Column can be a column number or a column name. To set the status for the row, enter 0 for column.
dwbuffer DWBuffer A value identifying the DataWindow buffer that contains the row
status DWItemStatus A value of the dwItemStatus enumerated data type (PowerBuilder) or an integer (Web ActiveX) or a string (Web DataWindow) specifying the new status.

# dataStore.getItemStatus(row, column, dwbuffer) ⇒ Number/NULL

Reports the modification status of a row or a column within a row. The modification status determines the type of SQL statement the Update method will generate for the row or column.

Kind: instance method of DataStore
Returns: Number/NULL - A value of the dwItemStatus enumerated data type. If any argument's value is NULL, in PowerBuilder and JavaScript the method returns NULL.

Param Type Description
row Number A value identifying the row for which you want the status.
column String/Number The column for which you want the status. Column can be a column number or a column name. The column number is the number of the column as it is listed in the Column Specification view of the DataWindow painter Specify 0 to get the status of the whole row.
dwbuffer DWBuffer A value identifying the DataWindow buffer that contains the row

# dataStore.update(accept, resetflag) ⇒ Number

Updates the database with the changes made in a DataWindow control or DataStore. Update can also call AcceptText for the current row and column before it updates the database.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs.

Param Type Default Description
accept Boolean true A boolean value specifying whether the DataWindow control or DataStore should automatically perform an AcceptText prior to performing the update TRUE (Default) Perform AcceptText. The update is canceled if the data fails validation. FALSE Do not perform AcceptText.
resetflag Boolean true A boolean value specifying whether dwcontrol should automatically reset the update flags TRUE (Default) Reset the flags. FALSE Do not reset the flags.

# dataStore.resetUpdate() ⇒ Number

Clears the update flags in the primary and filter buffers and empties the delete buffer of a DataWindow or DataStore.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs.

# dataStore.reset() ⇒ Number

Clears all the data from a DataWindow control or DataStore object.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs. The return value is usually not used.

# dataStore.setRow() ⇒ Number

Reports the number of the current row in a DataWindow control or DataStore object.

Kind: instance method of DataStore
Returns: Number - Returns the number of the current row in dwcontrol. Returns 0 if no row is current and -1 if an error occurs.

# dataStore.getRow(row) ⇒ Number

Reports the number of a row associated with a band in a DataWindow object or a report.

Kind: instance method of DataStore
Returns: Number - Returns the number of a row if it succeeds, 0 if no data has been retrieved or added, and -1 if an error occurs.

Param Type Description
row Number A value identifying the row before which you want to insert a row. To insert a row at the end, specify 0.

# dataStore.rowsMove(startrow, endrow, movebuffer, targetdw, beforerow, targetbuffer) ⇒ Number

Clears a range of rows from one DataWindow control (or DataStore) and inserts them in another. Alternatively, RowsMove moves rows from one buffer to another within a single DataWindow control (or DataStore).

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is NULL, in PowerBuilder and JavaScript the method returns NULL.

Param Type Description
startrow Number The number of the first row you want to move.
endrow Number The number of the last row you want to move.
movebuffer DWBuffer A value of the dwBuffer enumerated data type (PowerBuilder) or an integer (Web ActiveX) identifying the DataWindow buffer from which you want to move the rows.
targetdw DataStore The name of the DataWindow control or DataStore to which you want to move the rows. Targetdw can be the same DataWindow control (or DataStore) or a different DataWindow control (or DataStore), but it cannot be a child DataWindow.
beforerow Number The number of the row before which you want to insert the moved rows. To insert after the last row, use any value that is greater than the number of existing rows.
targetbuffer DWBuffer A value of the dwBuffer enumerated data type (PowerBuilder) or an integer (Web ActiveX) identifying the target buffer for the rows.

# dataStore.rowsCopy(startrow, endrow, copybuffer, targetdw, beforerow, targetbuffer) ⇒ Number

Copies a range of rows from one DataWindow control (or DataStore object) to another, or from one buffer to another within a single DataWindow control (or DataStore).

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is NULL, in PowerBuilder and JavaScript the method returns NULL.

Param Type Description
startrow Number The number of the first row you want to copy.
endrow Number The number of the last row you want to copy.
copybuffer DWBuffer A value of the dwBuffer enumerated data type (PowerBuilder) or an integer (Web ActiveX) identifying the DataWindow buffer from which you want to copy the rows.
targetdw DataStore The name of the DataWindow control or DataStore to which you want to copy the rows. Targetdw can be the same DataWindow control (or DataStore) or a different DataWindow control (or DataStore).
beforerow Number The number of the row before which you want to insert the copied rows. To insert after the last row, use any value that is greater than the number of existing rows.
targetbuffer DWBuffer A value of the dwBuffer enumerated data type (PowerBuilder) or an integer (Web ActiveX) identifying the target DataWindow buffer for the copied rows.

# dataStore.rowsDiscard(startrow, endrow, buffer) ⇒ Number

Discards a range of rows in a DataWindow control. Once a row has been discarded using RowsDiscard, you cannot restore the row. You have to retrieve it again from the database.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs.

Param Type Description
startrow Number The number of the first row you want to discard.
endrow Number The number of the last row you want to discard.
buffer DWBuffer A value of the dwBuffer enumerated data type (PowerBuilder) or an integer (Web ActiveX) or a string (Web DataWindow) specifying the DataWindow buffer containing the rows to be discarded.

# dataStore.setSort(format) ⇒ Number

Specifies sort criteria for a DataWindow control or DataStore.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs.

Param Type Description
format String A string whose value is valid sort criteria for the DataWindow (see Usage). The expression includes column names or numbers. A column number must be preceded by a pound sign (#). If format is NULL, PowerBuilder prompts you to enter the sort criteria.

# dataStore.sort() ⇒ Number

Sorts the rows in a DataWindow control or DataStore using the DataWindow's current sort criteria.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs. If dwcontrol is NULL, Sort returns NULL.

# dataStore.setFilter(format) ⇒ Number

Specifies filter criteria for a DataWindow control or DataStore.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs. If no DataWindow object has been assigned to the DataWindow or DataStore, SetFilter returns -1. The return value is usually not used.

Param Type Description
format String A string whose value is a boolean expression that you want to use as the filter criteria. The expression includes column names or numbers. A column number must be preceded by a pound sign (#). If format is NULL, PowerBuilder prompts you to enter a filter.

# dataStore.filter() ⇒ Number

Displays rows in a DataWindow that pass the current filter criteria. Rows that do not meet the filter criteria are moved to the filter buffer.

Kind: instance method of DataStore
Returns: Number - Returns 1 if it succeeds and -1 if an error occurs. The return value is usually not used. If dwcontrol is NULL, in PowerBuilder and JavaScript the method returns NULL.

# dataStore.find(expression, start, end) ⇒ Number

Finds the next row in a DataWindow or DataStore in which data meets a specified condition.

Kind: instance method of DataStore
Returns: Number - Returns the number of the first row that meets the search criteria within the search range. Returns 0 if no rows are found and one of these negative numbers if an error occurs: -1 General error -5 Bad argument

Param Type Description
expression String A string whose value is a boolean expression that you want to use as the search criterion. The expression includes column names.
start Number A value identifying the row location at which to begin the search. Start can be greater than the number of rows.
end Number A value identifying the row location at which to end the search. End can be greater than the number of rows. To search backward, make end less than start.

# dataStore.deletedCount() ⇒ Number

Reports the number of rows that have been marked for deletion in the database.

Kind: instance method of DataStore
Returns: Number - Returns the number of rows that have been deleted from dwcontrol but not updated in the associated database table. Returns 0 if no rows have been deleted or if all the deleted rows have been updated in the database table. DeletedCount returns -1 if it fails.

# dataStore.filteredCount() ⇒ Number

Reports the number of rows that are not displayed in the DataWindow because of the current filter criteria.

Kind: instance method of DataStore
Returns: Number - Returns the number of rows in dwcontrol that are not displayed because they do not meet the current filter criteria. Returns 0 if all rows are displayed and -1 if an error occurs.

# dataStore.modifiedCount() ⇒ Number

Reports the number of rows that have been modified but not updated in a DataWindow or DataStore.

Kind: instance method of DataStore
Returns: Number - Returns the number of rows that have been modified in the primary buffer. Returns 0 if no rows have been modified or if all modified rows have been updated in the database table. Returns -1 if an error occurs.

# dataStore.getChanges() ⇒ Number

Retrieves changes made to a DataWindow or DataStore as a blob. This method is used primarily in distributed applications.

Kind: instance method of DataStore
Returns: Number - Returns the number of rows in the DataWindow change blob if it succeeds and one of the following values if it fails: -1 An internal error occurred.

# dataStore.setChanges() ⇒ Number

Applies changes captured with GetChanges to a DataWindow or DataStore. This method is used primarily in distributed applications.

Kind: instance method of DataStore
Returns: Number - Returns one of the following values: 1 All changes were applied 2 A partial update was successful; conflicting changes were discarded -1 Method failed -2 There is a conflict between the state of the DataWindow changeblob and the state of the DataWindow -3 Column specifications do not match

# dataStore.on(eventName, callback) ⇒ Object

Register event callback. When event be fired, the callback will be called;

Kind: instance method of DataStore
Returns: Object - Returns current Object, allow multiple call

Param Type Description
eventName String can be value of DWEvent
callback function will be called

Example

dw1.on('ItemChanged',(row, name, data) => {
   console.log('ItemChanged',row, name,data);
 });
dw1.on('ItemFocusChanged',(row, name) => {
   console.log('ItemFocusChanged',row, name);
 });
dw1.on('RowFocusChanged',(row)=>{
   console.log('RowFocusChanged',row);
 });

# dataStore.off(eventName, callback) ⇒ Object

UnRegister event callback.

Kind: instance method of DataStore
Returns: Object - Returns current Object, allow multiple call

Param Type Default Description
eventName String can be value of DWEvent
callback function | NULL If callback is null, unRegister all callback.

Example

dw1.off('ItemChanged',dw_ItemChanged);
dw1.off('ItemFocusChanged');
dw1.off('RowFocusChanged');

# deepClone(source) ⇒ Object

This is just a simple version of deep copy Has a lot of edge cases bug If you want to use a perfect deep copy, use lodash's _.cloneDeep

Kind: global function

Param Type
source Object