All Implemented Interfaces
The RecordSet object lets you manipulate record sets returned from Flash Remoting or create client-side record sets. A record set is a list of records, with methods for fetching, accessing, and manipulating the list of records in various ways.
Record sets created on an application server usually consist of database query results. Each record in a RecordSet object is represented by an untyped ActionScript object. In a RecordSet object, individual records are identified by an index number. The index starts at zero. When the record set is sorted or a record is added to or deleted from the record set, the index changes.
Each field of the record is represented by a field in the object. For a RecordSet object that originated from an application server, the field names are the same as the field names defined by the server-side record set. For local RecordSet objects, the field names are the same as defined in the original call to the new RecordSet() function.
You can import the RecordSet class using the following import statement:
import mx.remoting.RecordSet;
columnNames property of the cartRecordSet RecordSet and adds the ID column if it is not already there.
var colNames:Array = cartRecordSet.columnNames;
var idFound:Boolean = true;
for( var i:Number = 0; i < colNames.length; i++ )
idFound = colNames[i] == "ID";
if( idFound != true )
scGrid.addColumnAt( 0, "ID" );
cartRecordSet RecordSet and computes the total price for all records in the shopping cart.
var cartItems:Array = cartRecordSet.items;
var total:Number = 0;
for( var i:Number=0;i<cartItems.length; i++ )
total += cartItems[i].price;
rs RecordSet from the length property.
totalRec_txt.text = String( rs.length );
modelChanged() function retrieves the length of RecordSet if any event has occurred that might affect the size of the RecordSet.
function modelChanged(eventObj : Object) : Void {
var event = eventObj.eventName;
if (event == "addItems" || event == "removeItems" ||
event=="updateAll" || event=="filterModel") {
total_txt.text = String( eventObj.target.length );
}
//
}
See Also
mx.remoting.RecordSet.addEventListener
mx.remoting.RecordSet.removeEventListener
| Constructors | |
RecordSet
(
columnNames)
Creates a new local RecordSet object with the specified column names, which is initially empty. Local RecordSet objects never download data from an application server; the RecordSet methods related to data delivery are not available to local RecordSet objects.
|
|
| Methods | |
| addEventListener(
event:
String, listener)
: VoidRegisters a listener object with a modelChanged event that affects a RecordSet object. |
| addItem(
item:
Object)
: VoidInserts a record into the RecordSet object. |
| addItemAt(
index:
Number, item:
Object)
: VoidInserts a record into the RecordSet object at the specified index position. |
| clear(
)
: VoidRemoves all items from the record set. |
| contains(
itmToCheck:
Object)
: BooleanDetermines whether the record set contains the specified record. |
| editField(
index:
Number, fieldName:
String, value:
Object)
: VoidReplaces the value in one field of a record with a new value. |
| filter(
filterFunction:
Function, context)
: RecordSetCreates a new RecordSet object by calling the filterFunction() function once for each record in the RecordSet object and collecting, into a new RecordSet object, all records for which the filterFunction() function returns a value of true. |
| getColumnNames(
)
: ArrayReturns the names of all the columns of a RecordSet object as an array of strings. |
| getEditingData(
index:
Number, fieldName:
String)
: ObjectRetrieves data for editing from a data provider (record set). |
| getItemAt(
index:
Number)
: ObjectReturns a record if the index is valid and the record is immediately available. |
| getItemID(
index:
Number)
: ObjectReturns the unique ID for the record at the specified index. |
| getIterator(
)
: IteratorReturns a new iterator on this RecordSet object (collection). |
| getLength(
)
: NumberNote: This method is superseded by the length property. |
| getLocalLength(
)
: NumberReturns the number of records currently available (or downloaded locally). |
| getNumberAvailable(
)
: NumberReturns the number of records that have been downloaded from the server. |
| getRemoteLength(
)
: NumberReturns the number of records in the RecordSet object on the server side. |
| isEmpty(
)
: BooleanDetermines whether the RecordSet object is empty. |
| isFullyPopulated(
)
: BooleanDetermines whether a RecordSet object is fully populated, meaning that it has all its records. |
| isLocal(
)
: BooleanDetermines whether a RecordSet object is local or, if the record set is associated with an application server, whether records remain to be retrieved from the application server. |
| removeAll(
)
: VoidRemoves all records from the record set, in a way similar to the RecordSet. |
| removeEventListener(
event:
String, listener)
: VoidRemoves the specified event listener. |
| removeItemAt(
index:
Number)
: ObjectRemoves the specified record. |
| replaceItemAt(
index:
Number, item:
Object)
: VoidReplaces a record in the RecordSet object at the specified index. |
| setDeliveryMode(
mode:
String, pagesize:
Number, numPrefetchPages:
Number)
: VoidChanges the delivery mode of a record set associated with an application server. |
| setField(
index:
Number, fieldName:
String, value:
Object)
: VoidNote: This method is superceeded by the RecordSet. |
| sort(
compareFunc:
Function)
: VoidSorts all the records using a user-specified comparison function. |
| sortItems(
compareFunc:
Function, optionFlags:
Number)
: VoidSorts all the records using a user-specified comparison function. |
| sortItemsBy(
fieldNames:
Array, order:
String, optionFlags:
Number)
: VoidSorts all records in the RecordSet object without making a new copy. |
| Properties | |
static | version:
String Component version. |
| columnNames:
Array [
Read-Only]
Returns the names of all the columns of a RecordSet object as an array of strings. |
| length:
Number [
Read-Only]
Returns the number of records currently available, or downloaded locally, in a RecordSet object. |
| items:
Array [
Read-Only]
Returns an array of all records of the RecordSet. |
| Constructor Detail |
RecordSet(
columnNames)
Parameters
columnNames:
Array - An array of strings in which each string is a name of one of the record set columns.
productList with the columns ProductName, Price, and Color:
import mx.remoting.RecordSet;
var productList:RecordSet = new RecordSet(["ProductName", "Price", "Color"]);
| Method Detail |
addEventListener(
event:
String, listener)
: Void
modelChanged event that affects a RecordSet object. When the event is triggered, the listener object or function is notified. You can call this method from any RecordSet instance. For example, the following code registers a listener, myListener, that is called when a modelChanged event occurs for the RecordSet instance myRecs:
myRecs.addEventListener("modelChanged", myListener);
You must define the listener as either an object or a function before you call addEventListener() to register the listener with the record set. If the listener is an object, it must have a callback function defined that is invoked when the event is triggered. Usually, that callback function has the same name as the event with which the listener is registered. For example, if the event is modelChanged, then the name of the function would be modelChanged(). If the listener is a function, the function is invoked when the event is triggered.
You can register multiple listeners to a single record set, but you must use a separate call to addEventListener() for each listener. Also, you can register one listener to multiple record sets, but you must use a separate call to addEventListener() for each instance. For example, the following code defines one listener object, myListener, and assigns it to two RecordSet objects, myRecs and coRecs:
import mx.remoting.RecordSet;
myRecs = new RecordSet(); // create 1st local RecordSet
coRecs = new RecordSet(); // create 2nd local RecordSet
myListener = new Object(); // create listener object
myListener.modelChanged = function(evt){ // create event handler function
if (evt.eventName == "addItems"){ // check type of event
trace("Records added");
} else if (evt.eventName == "removeItems"){ // check type of event
trace("Records removed");
}
}
myRecs.addEventListener("modelChanged", myListener); // reg. myRecs listener
coRecs.addEventListener("modelChanged", myListener); // reg. coRecs listener
Execution order is not guaranteed. You cannot rely on one listener being called before another.
The modelChanged event object is passed to the listener as a parameter. The event object has properties that contain information about the event that occurred. You can use the event object in the listener callback function to access information about what type of event occurred and which instance broadcast the event. In the preceding example, the event object is evt (you can use any identifier as the event object name) and eventname is used in the if statement to determine more specifically what type of event occurred on the record set. For more information, see Event handler summary for the RecordSet class.
Parameters
event:
String - A string that specifies the name of the event that triggers the listener.
listener - A reference to a listener object or function that is called when the event occurs.
categoryId value of "B" that are added or removed from the billableCustomers_rs RecordSet:
import mx.remoting.RecordSet;
import com.mycompany.crm.*;
var billableCustomers_rs:RecordSet = new RecordSet(["name","categoryId"]);
var bcHandler:BillableCustomerDisplayHandler = new BillableCustomerDisplayHandler(billable_txt,billableCustomers_rs);
The following is the class file BillableCustomerDisplayHandler.as that should be located in the com.mycompany.crm classpath directory:
import mx.remoting.RecordSet;
import mx.controls.TextInput;
class com.mycompany.crm.BillableCustomerDisplayHandler extends Object {
function BillableCustomerDisplayHandler( textCtrl:TextInput, rs:RecordSet ) {
super();
_billableCustomers = textCtrl;
rs.addEventListener( "modelChanged", this );
}
function modelChanged( evt:Object ):Void {
if( evt.eventName == "addItems" ) {
var rs:RecordSet = RecordSet( evt.target );
if( rs.items[evt.firstItem].categoryId == "B" )
_billableCustomers.text = String(Number( _billableCustomers.text ) +1);
} else if( evt.eventName == "removeItems" ) {
for( var i:Number=0; i<evt.lastItem - evt.firstItem; i++ ) {
if( evt.removedItems[i].categoryId == "B" )
_billableCustomers.text = String(Number( _billableCustomers.text ) -1);
} // for
} // else
}
private var _billableCustomers:mx.controls.TextInput;
}
See Also
mx.remoting.RecordSet.addItem
mx.remoting.RecordSet.addItemAt
mx.remoting.RecordSet.removeEventListener
mx.remoting.RecordSet.sortItems
addItem(
item:
Object)
: Void
addItem() method, make sure that:
record parameter is an object.record parameter has no unknown or missing fields.record parameter is not an object. The record is added to the RecordSet object.
record parameter has unknown or missing fields. The record is added to the RecordSet object.
Operation not allowed on partial RecordSet objects.
Parameters
item:
Object - An object that is the item to add to the record set.
myRecordSet RecordSet object:
import mx.remoting.RecordSet;
var myItem:Object = {name: "John", age:44, phone: "415-999-9999"};
var myRecordSet:RecordSet = new RecordSet();
myRecordSet.addItem(myItem);
See Also
mx.remoting.RecordSet.RecordSet
mx.remoting.RecordSet.addItemAt
addItemAt(
index:
Number, item:
Object)
: Void
addItemAt() method, make sure that:
index specifies a location within the RecordSet.record parameter is a record object.record parameter has no unknown or missing fields.record parameter is not an object. The record is added to the RecordSet object.
record parameter contains unknown or missing fields. The record is added to the RecordSet object.
Parameters
index:
Number - The index number of the record.
item:
Object - The item to add to the RecordSet object.
myRecordSet RecordSet object:
import mx.remoting.RecordSet;
var myItem:Object = {name: "John", age:44, phone: "415-999-9999"};
var myRecordSet:RecordSet = new RecordSet();
myRecordSet.addItemAt(0,myItem);
The following example adds an item to the end of an existing myRecordSet RecordSet:
var myItem:Object = {name: "Debbie", age:39, phone: "415-999-9999"};
myRecordSet.addItemAt(myRecordSet.getLength(),myItem);
See Also
mx.remoting.RecordSet.RecordSet
mx.remoting.RecordSet.addItem
mx.remoting.RecordSet.removeItemAt
mx.remoting.RecordSet.replaceItemAt
mx.remoting.RecordSet.isFullyPopulated
clear(
)
: Void
clear() method when the RecordSet object is associated with an application server and is not fully populated yet. The following example illustrates how to handle this condition.
If the RecordSet object is server associated and not fully populated yet, no change is made to the RecordSet object and the following error message is reported to the Flash Output panel and Debug Console:
Operation not allowed on partial RecordSet objects.
Example
myRecordSet RecordSet :
if( myRecordSet.isFullyPopulated())
myRecordSet.clear();
See Also
mx.remoting.RecordSet.removeItemAt
mx.remoting.RecordSet.replaceItemAt
mx.remoting.RecordSet.isFullyPopulated
contains(
itmToCheck:
Object)
: Boolean
Parameters
itmToCheck:
Object - An object containing the item that you are seeking in the record set.
Returns
The Boolean value true if the record set contains the record; false if it does not.
myRec object to the existing myRecordSet RecordSet object, if the record does not already exist there.
var myRec:Object = {name:"Larry", age:34, phone:"415-999-9999"};
if(myRecordSet.contains(myRec) != true)
myRecordSet.addItem(myRec);
See Also
mx.remoting.RecordSet.filter
mx.remoting.RecordSet.isEmpty
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.isLocal
editField(
index:
Number, fieldName:
String, value:
Object)
: Void
index specifies a location within the RecordSet object.fieldName parameter specifies a valid column name.
Parameters
index:
Number - A number that specifies the index of the item.
fieldName:
String - A string that specifies the name of the field in which to place the new value.
value:
Object - A value to replace the value in the field specified by fieldName.
price field for each item in the shopping cart record set, cart_rs, to provide a 20% discount. It calls the editField() method to update the price field with the new discounted price:
var curPrice:Number = 0;
for( var i:Number = 0; i < cart_rs.length; i++ )
{
curPrice = cart_rs.items[i].price * 0.8; //20% discount
cart_rs.editField(i, "price", curPrice );
}
See Also
mx.remoting.RecordSet.contains
mx.remoting.RecordSet.filter
mx.remoting.RecordSet.replaceItemAt
filter(
filterFunction:
Function, context)
: RecordSet
filterFunction() function once for each record in the RecordSet object and collecting, into a new RecordSet object, all records for which the filterFunction() function returns a value of true. The order of the filtered records in the new RecordSet object is the same as their order in the original RecordSet object. The order in which the original RecordSet object is traversed during the filtering process is not defined.
If used on a RecordSet object that is not fully populated, only the currently available records are filtered. The new RecordSet object does not inherit the original RecordSet object's list of views, nor any association with a server-side RecordSet object.
Parameters
filterFunction:
Function - An ActionScript function that takes one or two parameters and returns a Boolean value of true or false. The first parameter is a single record from the RecordSet object. The second, optional, parameter is a context value that the function uses to determine whether to include the record in the result. The function must return a value of true if the record should be included in the filtered RecordSet object that is returned to the function specified by filterFunction.
context - Optional. A context value supplied by the caller. This value is the second parameter to the filterFunction function.
Returns
A new RecordSet object that contains a reference to, not a copy of, all the records that were selected by the filterFunction() function.
myRecordSet RecordSet object for records with an ID value less than or equal to 5. The resulting RecordSet is assigned to the dataProvider property of an existing Grid component:
// the filter function receives a record object from the record set and a
// value to use in filtering.
function contactFilter(aRecord:Object, aContext ):Boolean {
return (aRecord.ID <= aContext ); // true for records that have ID <= 5
}
myDataGrid.dataProvider = myRecordSet.filter(contactFilter, 5);
See Also
mx.remoting.RecordSet.contains
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.sortItems
getColumnNames(
)
: Array
Returns
An array of strings. The array is either the same array that you passed to the RecordSet constructor, or the equivalent array for a RecordSet object associated with an application server.
shoppingCart_rs contains an ID column:
import mx.remoting.RecordSet;
var colNames:Array = shoppingCart_rs.getColumnNames();
var idFound:Boolean = false;
for( var i:Number = 0; i < colNames.length; i++ ) {
if (colNames[i] == "ID") {
idFound = true;
i = colNames.length;
}
}
if( idFound )
scGrid.addColumnAt( 0, "ID" );
See Also
mx.remoting.RecordSet.RecordSet
getEditingData(
index:
Number, fieldName:
String)
: Object
Parameters
index:
Number - The index of the item to retrieve. The value of index can range from >=0 to < dp.length (where dp is the data provider or RecordSet).
fieldName:
String - Specifies the name of the field being edited.
Returns
An object containing the data, in editable format, for the field at the specified index.
cart_rs when the user clicks the price_txt text field. For this example to work, there must be an existing Grid component containing cart_rs data:
var focusListener:Object = new Object();
focusListener.onSetFocus = function(oldFocus_txt, newFocus_txt):Void {
if (newFocus_txt._name = "price_txt") {
var index:Number = cart_grd.selectedIndex;
newFocus_txt.text = cart_rs.getEditingData(index,"price");
}
}
Selection.addListener(focusListener);
getItemAt(
index:
Number)
: Object
"in progress". Remember that indexes to the records in a set change when the record set is sorted, and when records are deleted or added.
Parameters
index:
Number - The index number of the record to retrieve.
Returns
The item at the specified index or null if none exists.
cart_rs RecordSet object by 30%:
for( var i:Number = 0; i < cart_rs.length; i++ )
cart_rs.getItemAt(i).price *= 0.7; // reduce the price by 30%
See Also
mx.remoting.RecordSet.RecordSet
mx.remoting.RecordSet.addItemAt
getItemID(
index:
Number)
: Object
Parameters
index:
Number - The index number of the item in the record set.
Returns
An object that is the unique identification (ID) corresponding to the record at the specified index. Returns null if the index is out of range.
cart_rs record set, which consists of the records from a Grid component. Subsequently, the code searches the cart_rs RecordSet to see if the bookmarked record is still in the RecordSet:
var bookmark:Object = cart_rs.getItemID(cart_grd.selectedIndex);
// later in the program:
var found:Boolean = true;
var i:Number = 0;
while( !found && i < cart.length )
found = bookmark == cart_rs.getItemID(i++);
See Also
mx.remoting.RecordSet.sortItems
mx.remoting.RecordSet.sortItemsBy
getIterator(
)
: Iterator
Iterator is an interface that is defined as follows:
interface mx.utils.Iterator
{
function hasNext():Boolean;
function next():Object;
}
Returns
An Iterator interface that is the new iterator for this record set.
cart_rs RecordSet object:
import mx.utils.Iterator;
// var total:Number = 0;
var it:Iterator = cart_rs.getIterator();
while( it.hasNext())
total += it.next().price;
See Also
mx.remoting.RecordSet.RecordSet
getLength(
)
: Number
length property.
Returns the number of records currently available, or downloaded locally, in a RecordSet object. The length of the record set on the client side depends on the delivery mode. In the onDemand and page delivery modes, the value of the length property is equal to the length of the local record set. In the fetchAll delivery mode, the length is equal to the length of the remote record set.
Returns
A number that is the total number of items in the local RecordSet object.
totalRec_txt text field the total number of records in the existing cart_rs RecordSet object:
totalRec_txt.text = String( cart_rs.getLength());
See Also
mx.remoting.RecordSet.length
mx.remoting.RecordSet.getLocalLength
mx.remoting.RecordSet.getRemoteLength
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.setDeliveryMode
getLocalLength(
)
: Number
page mode, the length is equal to the local length of the record set. In fetchAll mode, the length equals the length of the remote record set.
Returns
A number that specifies the length of the local RecordSet object.
totalRec_txt text field the total number of records in the existing cart_rs RecordSet object:
totalRec_txt.text = String( cart_rs.getLocalLength());
See Also
mx.remoting.RecordSet.length
mx.remoting.RecordSet.getLength
mx.remoting.RecordSet.getRemoteLength
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.setDeliveryMode
getNumberAvailable(
)
: Number
getLocalLength() method.
Returns
A number that is the number of records that have been downloaded from the server.
totalRec_txt text field the total number of records available in an existing RecordSet object named cart_rs:
totalRec_txt.text = String( cart_rs.getNumberAvailable());
See Also
mx.remoting.RecordSet.length
mx.remoting.RecordSet.getLocalLength
mx.remoting.RecordSet.getRemoteLength
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.isLocal
mx.remoting.RecordSet.setDeliveryMode
getRemoteLength(
)
: Number
Returns
A number that specifies the number of records in the RecordSet object on the server side.
totalRec_txt text field the total number of records available in an existing server side RecordSet object named cart_rs:
totalRec_txt.text = String( cart_rs.getRemoteLength());
See Also
mx.remoting.RecordSet.length
mx.remoting.RecordSet.getLocalLength
mx.remoting.RecordSet.getNumberAvailable
mx.remoting.RecordSet.getRemoteLength
mx.remoting.RecordSet.setDeliveryMode
isEmpty(
)
: Boolean
Returns
A Boolean value of true if the RecordSet object is empty; false otherwise.
edit_btn button if the existing RecordSet object shoppingCart_rs is empty:
edit_btn.enabled = !shoppingCart_rs.isEmpty();
See Also
mx.remoting.RecordSet.isFullyPopulated
isFullyPopulated(
)
: Boolean
addItem()addItemAt()replaceItemAt()setField()removeItem()removeAll()filter()sort()RecordSet.isLocal() method.
Returns
Returns a Boolean value of true if the RecordSet object is fully populated; false if it is not.
sort_btn button if the books_rs RecordSet object is fully populated.
sort_btn.enabled = books_rs.isFullyPopulated();
See Also
mx.remoting.RecordSet.isEmpty
mx.remoting.RecordSet.isLocal
mx.remoting.RecordSet.length
mx.remoting.RecordSet.getLocalLength
mx.remoting.RecordSet.getRemoteLength
isLocal(
)
: Boolean
RecordSet.isFullyPopulated() method.
Returns
A Boolean value of true if the RecordSet object is local and false if records remain to be retrieved from the application server.
sort_btn button if the books_rs RecordSet object is local.
sort_btn.enabled = books_rs.isLocal();
See Also
mx.remoting.RecordSet.getLocalLength
mx.remoting.RecordSet.isFullyPopulated
removeAll(
)
: Void
RecordSet.clear() method. Do not use the removeAll() method when the RecordSet object is associated with an application server and it is not fully populated yet.
If the RecordSet object is server associated and not fully populated yet no change is made to the RecordSet object, and the following error message is reported to the Flash Output panel and Debug Console:
Operation not allowed on partial RecordSet objects.
Example
myRecordSet.removeAll();
trace(myRecordSet.length); // outputs 0 to trace window
See Also
mx.remoting.RecordSet.isEmpty
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.removeItemAt
removeEventListener(
event:
String, listener)
: Void
Parameters
event:
String - A string that specifies the name of the event.
listener - A reference to a listener object or function.
shoppingCart_rs RecordSet object:
shoppingCart_rs.removeEventListener("modelChanged", myListener);
See Also
mx.remoting.RecordSet.addEventListener
removeItemAt(
index:
Number)
: Object
removeItemAt() method, make sure that the following conditions are met:
Operation not allowed on partial RecordSet objects.
Parameters
index:
Number - The index number of the record.
shoppingCart_rs RecordSet object:
function deleteConfirmed( indexToRemove:Number ):Void {
shoppingCart_rs.removeItemAt( indexToRemove );
}
See Also
mx.remoting.RecordSet.RecordSet
mx.remoting.RecordSet.addItem
mx.remoting.RecordSet.addItemAt
mx.remoting.RecordSet.getItemID
mx.remoting.RecordSet.replaceItemAt
replaceItemAt(
index:
Number, item:
Object)
: Void
item parameter. The record's ID does not change. When you use the replaceItemAt() method, make sure that the following conditions are met:
Operation not allowed on partial RecordSet objects.
Parameters
index:
Number - A number that specifies the index number of the record.
item:
Object - The record to add.
contacts_rs RecordSet with a new record:
var myItem:Object = {name:"Kerry", age:45, phone:"415-999-9999"};
contacts_rs.replaceItemAt(9, myItem);
See Also
mx.remoting.RecordSet.RecordSet
mx.remoting.RecordSet.addItem
mx.remoting.RecordSet.addItemAt
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.removeItemAt
setDeliveryMode(
mode:
String, pagesize:
Number, numPrefetchPages:
Number)
: Void
pagesize parameter. The entire record set is "fetched" (retrieved) from the application server in a series of requests, and each request fetches only the number of records specified in the pagesize parameter.
When using page mode, you can supply the pagesize and numPrefetchPages parameters. In page mode, when you request a record using the getItemAt() method, the RecordSet object ensures that those pages to be prefetched after the page containing the requested record are either already available in the client or requested from the server. If the value of numPrefetchPages is zero, only the current page containing the requested record is fetched.
When the RecordSet object is fully populated, the setDeliveryMode method has no effect.
If the mode string has an unknown value, no change is made to the RecordSet object, and the following error message is reported to the Flash Output panel and Debug Console:
SETDELIVERYMODE: unknown mode string
Parameters
mode:
String - A string that identifies the delivery mode. The options are onDemand (default), fetchAll, and page.
pagesize:
Number - An optional parameter that, in page mode, is a number that specifies what the page size is. In fetchall mode, the parameter is a number that specifies how many records to fetch in each server request. The default is 25.
numPrefetchPages:
Number - An optional parameter that, in page mode, is a number that specifies the number of pages to prefetch. The default is 0, which fetches only the requested page.
contacts_rs delivery mode to page, with a page size corresponding to the number of rows in myGrid_grd. The number of prefetch pages is set to 10:
contacts_rs.setDeliveryMode("page", myGrid_grd.getRowCount(), 10);
See Also
mx.remoting.RecordSet.getItemAt
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.isLocal
setField(
index:
Number, fieldName:
String, value:
Object)
: Void
RecordSet.editField() method.
Replaces one field of a record with a new value.
When you use the setField() method, make sure that the following conditions are met:
fieldName parameter specifies a valid column name. Operation not allowed on partial RecordSet objects.
- Index out of range
The RecordSet object is not changed.
Parameters
index:
Number - The index number of the record.
fieldName:
String - The field name to replace.
value:
Object - A value to replace the value in the field specified by fieldName.
price field for each item in the existing cart_rs RecordSet object to provide a 20% discount:
var curPrice:Number = 0;
for( var i:Number = 0; i < cart_rs.length; i++ ) {
curPrice.price = cart_rs.items[i].price * 0.8; //20% discount
cart_rs.setField(i, "price", curPrice );
}
See Also
mx.remoting.RecordSet.RecordSet
mx.remoting.RecordSet.editField
sort(
compareFunc:
Function)
: Void
sort() method sorts all the records in place, without making a new copy. The order is determined by the user-supplied compareFunc() function. The original order is not remembered.
When you use the sort() method, avoid sorting a RecordSet object that is associated with an application server and not fully populated yet.
If the RecordSet object is not fully populated no change is made to the RecordSet object, and the following error message is reported to the Flash Output panel and Debug Console.
Operation not allowed on partial RecordSet objects.
Parameters
compareFunc:
Function - An ActionScript comparison function that determines the sorting order. Given the arguments A and B, the comparison function returns a value as follows:
contacts_rs by calling the function sortContacts(), two records at a time, to sort by the lastname field:
function sortContacts(a:Object,b:Object):Number {
if ( a.lastname < b.lastname)
return( -1 );
else if ( a.lastname == b.lastname)
return( 0 );
else return( 1 );
}
contacts_rs.sort(sortContacts);
See Also
mx.remoting.RecordSet.filter
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.isLocal
mx.remoting.RecordSet.sortItems
mx.remoting.RecordSet.sortItemsBy
sortItems(
compareFunc:
Function, optionFlags:
Number)
: Void
sort() method sorts all the records in place, without making a new copy. The order is determined by the user-supplied compareFunc() function. The original order is not remembered.
Parameters
compareFunc:
Function - An ActionScript comparison function that determines the sorting order. Given the arguments A and B, the comparison function returns a value as follows: -1 if A appears before B in the sorted sequence 0 if A = B 1 if A appears after B in the sorted sequence
optionFlags:
Number - One or more numbers or strings, separated by the bitwise OR operator
( | ), that change the behavior of the sort from the default. The following values are valid: Array.CASEINSENSITIVE Array.DESCENDING Array.UNIQUESORT Array.RETURNINDEXEDARRAY Array.NUMERIC
contacts_rs RecordSet object by calling the function sortContacts(), two records at a time, to numerically sort by the age field:
function sortContacts(a:Object,b:Object):Number {
if ( a.age < b.age)
return( -1 );
else if ( a.age == b.age)
return( 0 );
else return( 1 );
}
contacts_rs.sortItems(sortContacts, Array.NUMERIC);
See Also
mx.remoting.RecordSet.filter
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.isLocal
mx.remoting.RecordSet.sortItemsBy
sortItemsBy(
fieldNames:
Array, order:
String, optionFlags:
Number)
: Void
fieldNames parameter identifies a field that does not exist in one or more records, then null is used as the key value for those records. The value null appears lower in the sort order than any other value.
The sortItemsBy() method may be used only with fully populated RecordSet objects.
If the RecordSet object is server associated but not fully populated no change is made to the RecordSet object, and an error message is reported to the Flash Output panel and Debug Console:
Operation not allowed on partial RecordSet objects.
Parameters
fieldNames:
Array - A string or an array of strings that represents the field or fields on which sorting needs to be done. The first field name represents the primary sort field, the second represents the next sort field, and so on.
order:
String - A String specifying whether to sort the items in ascending order ("ASC") or descending order ("DESC").
optionFlags:
Number - One or more numbers or strings, separated by the bitwise OR operator ( | ), that change the behavior of the sort from the default. The following values are valid: Array.CASEINSENSITIVE Array.DESCENDING Array.UNIQUESORT Array.RETURNINDEXEDARRAY Array.NUMERIC.
Returns
A Boolean value of true if the sort succeeds; false if any errors occurred.
contacts_rs RecordSet object by the lastname and firstname fields. The case is ignored and the sort is performed in descending order:
var sortOptions:Number = Array.CASEINSENSITIVE | Array.DESCENDING;
contacts_rs.sortItemsBy(["lastname","firstname"], null, sortOptions);
See Also
mx.remoting.RecordSet.addEventListener
mx.remoting.RecordSet.filter
mx.remoting.RecordSet.isFullyPopulated
mx.remoting.RecordSet.sortItems
| Property Detail |
columnNames:
Array [
Read-Only]
items:
Array [
Read-Only]
length:
Number [
Read-Only]
length property is equal to the length of the local record set. In the fetchAll delivery mode, the length is equal to the length of the remote record set.
static
version:
String
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flashremoting/mx2004/actionscript_api_reference/mx/remoting/RecordSet.html