# Class Ext.data.Record

Package: | Ext.data
Defined In: | Record.js
Class: | Record
Extends: | Object

Instances of this class encapsulate both Record definition information, and Record value information for use in Ext.data.Store objects, or any code which needs to access Records cached in an Ext.data.Store object.

Constructors for this class are generated by passing an Array of field definition objects to create. Instances are usually only created by Ext.data.Reader implementations when processing unformatted data objects.

Note that an instance of a Record class may only belong to one Store at a time. In order to copy data from one Store to another, use the copy method to create an exact copy of the Record, and insert the new instance into the other Store.

When serializing a Record for submission to the server, be aware that it contains many private properties, and also a reference to its owning Store which in turn holds references to its Records. This means that a whole Record may not be encoded using Ext.util.JSON.encode. Instead, use the `data` and `id` properties.

Record objects generated by this constructor inherit all the methods of Ext.data.Record listed below.

## Public Properties

Property | Defined By
--- | ---
| data : Object An object hash representing the data for this Record. Every field name in the Record definition is represented by a p... An object hash representing the data for this Record. Every field name in the Record definition is represented by a property of that name in this object. Note that unless you specified a field with name "id" in the Record definition, this will not contain an `id` property. | Record
| dirty : Boolean Readonly flag - true if this Record has been modified. | Record
| fields : Ext.util.MixedCollection This property is stored in the Record definition's prototype A MixedCollection containing the defined Fields for this... This property is stored in the Record definition's prototype A MixedCollection containing the defined Fields for this Record. Read-only. | Record
| id : Object The unique ID of the Record as specified at construction time. | Record
| json : Array|Object Only present if this Record was created by an ArrayReader or a JsonReader. The Array or object which was the source o... Only present if this Record was created by an ArrayReader or a JsonReader. The Array or object which was the source of the data for this Record. | Record
| modified : Object This object contains a key and value storing the original values of all modified fields or is null if no fields have ... This object contains a key and value storing the original values of all modified fields or is null if no fields have been modified. | Record
| node : XMLElement Only present if this Record was created by an XmlReader. The XML element which was the source of the data for this Re... Only present if this Record was created by an XmlReader. The XML element which was the source of the data for this Record. | Record
| phantom : Boolean true when the record does not yet exist in a server-side database (see markDirty). Any record which has a real datab... `true` when the record does not yet exist in a server-side database (see markDirty). Any record which has a real database pk set as its id property is NOT a phantom -- it's real. | Record
| store : Ext.data.Store The Ext.data.Store to which this Record belongs. | Record

## Public Methods

Method | Defined By
--- | ---
| Record( [`Object data`], [`Object id`] ) This constructor should not be used to create Record objects. Instead, use create to generate a subclass of Ext.data.... This constructor should not be used to create Record objects. Instead, use create to generate a subclass of Ext.data.Record configured with information about its constituent fields. The generated constructor has the same signature as this constructor. Parameters: `data` : Object (Optional) An object, the properties of which provide values for the new Record's fields. If not specified the `defaultValue` for each field will be assigned. `id` : Object (Optional) The id of the Record. The id is used by the Ext.data.Store object which owns the Record to index its collection of Records (therefore this id should be unique within each store). If an `id` is not specified a `phantom` Record will be created with an automatically generated id. Returns: void | Record
| Record.id( `Record rec` ) : String Generates a sequential id. This method is typically called when a record is created and no id has been specified. The... Generates a sequential id. This method is typically called when a record is created and no id has been specified. The returned id takes the form: `{PREFIX}-{AUTO_ID}`. `PREFIX` : String `Ext.data.Record.PREFIX` (defaults to `'ext-record'`) `AUTO_ID` : String `Ext.data.Record.AUTO_ID` (defaults to `1` initially) Parameters: `rec` : Record The record being created. The record does not exist, it's a phantom. Returns: `String` auto-generated string id, <tt>"ext-record-i++'</tt>; | Record
| beginEdit() : void Begin an edit. While in edit mode, no events (e.g.. the update event) are relayed to the containing store. See also: ... Begin an edit. While in edit mode, no events (e.g.. the `update` event) are relayed to the containing store. See also: `endEdit` and `cancelEdit`. Parameters: None. Returns: void | Record
| cancelEdit() : void Cancels all changes made in the current edit operation. Cancels all changes made in the current edit operation. Parameters: None. Returns: void | Record
| commit( [`Boolean silent`] ) : void Usually called by the Ext.data.Store which owns the Record. Commits all changes made to the Record since either creat... Usually called by the Ext.data.Store which owns the Record. Commits all changes made to the Record since either creation, or the last commit operation. Developers should subscribe to the Ext.data.Store.update event to have their code notified of commit operations. Parameters: `silent` : Boolean (optional) True to skip notification of the owning store of the change (defaults to false) Returns: void | Record
- | copy( [`String id`] ) : Record Creates a copy (clone) of this Record. Creates a copy (clone) of this Record. Parameters: `id` : String (optional) A new Record id, defaults to the id of the record being copied. See `id`. To generate a phantom record with a new id use:
      var rec = record.copy(); // clone the record
      Ext.data.Record.id(rec); // automatically generate a unique sequential id
Returns: `Record` | Record
- | create( `Array o` ) : function <static> Generate a constructor for a specific Record layout. <static> Generate a constructor for a specific Record layout. Parameters: `o` : Array An Array of Field definition objects. The constructor generated by this method may be used to create new Record instances. The data object must contain properties named after the field `Ext.data.Field.names`. Example usage:
      // create a Record constructor from a description of the fields
      var TopicRecord = Ext.data.Record.create([ // creates a subclass of Ext.data.Record
          {name: 'title', mapping: 'topic_title'},
          {name: 'author', mapping: 'username', allowBlank: false},
          {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
          {name: 'lastPost', mapping: 'post_time', type: 'date'},
          {name: 'lastPoster', mapping: 'user2'},
          {name: 'excerpt', mapping: 'post_text', allowBlank: false},
          // In the simplest case, if no properties other than name are required,
          // a field definition may consist of just a String for the field name.
          'signature'
      ]);

      // create Record instance
      var myNewRecord = new TopicRecord(
          {
              title: 'Do my job please',
              author: 'noobie',
              totalPosts: 1,
              lastPost: new Date(),
              lastPoster: 'Animal',
              excerpt: 'No way dude!',
              signature: ''
          },
          id // optionally specify the id of the record otherwise one is auto-assigned
      );
      myStore.add(myNewRecord);
Returns: `function` A constructor which is used to create new Records according to the definition. The constructor has the same signature as {@link #Record}. | Record
| endEdit() : void End an edit. If any data was modified, the containing store is notified (ie, the store's update event will fire). End an edit. If any data was modified, the containing store is notified (ie, the store's `update` event will fire). Parameters: None. Returns: void | Record
| get( `String name` ) : Object Get the value of the named field. Get the value of the named field. Parameters: `name` : String The name of the field to get the value of. Returns: `Object` The value of the field. | Record
| getChanges() : Object Gets a hash of only the fields that have been modified since this Record was created or commited. Gets a hash of only the fields that have been modified since this Record was created or commited. Parameters: None. Returns: `Object` | Record
| isModified( `String fieldName` ) : Boolean Returns true if the passed field name has been modified since the load or last commit. Returns `true` if the passed field name has been `modified` since the load or last commit. Parameters: `fieldName` : String Ext.data.Field#name Returns: `Boolean` | Record
| isValid() : Boolean By default returns false if any field within the record configured with Ext.data.Field.allowBlank = false returns tru... By default returns `false` if any field within the record configured with `Ext.data.Field.allowBlank = false` returns `true` from an Ext.isempty test. Parameters: None. Returns: `Boolean` | Record
| markDirty() : void Marks this Record as dirty. This method is used interally when adding phantom records to a writer enabled store. Mar... Marks this Record as `dirty`. This method is used interally when adding `phantom` records to a writer enabled store. Marking a record `dirty` causes the phantom to be returned by Ext.data.Store.getModifiedRecords where it will have a create action composed for it during store save operations. Parameters: None. Returns: void | Record
| reject( [`Boolean silent`] ) : void Usually called by the Ext.data.Store which owns the Record. Rejects all changes made to the Record since either creat... Usually called by the Ext.data.Store which owns the Record. Rejects all changes made to the Record since either creation, or the last commit operation. Modified fields are reverted to their original values. Developers should subscribe to the Ext.data.Store.update event to have their code notified of reject operations. Parameters: `silent` : Boolean (optional) True to skip notification of the owning store of the change (defaults to false) Returns: void | Record
| set( `String name`, `String/Object/Array value` ) : void Set the named field to the specified value. For example: // record has a field named 'firstname' var Employee = Ext.... Set the named field to the specified value. For example:
    // record has a field named 'firstname'
    var Employee = Ext.data.Record.create([
        {name: 'firstname'},
        ...
    ]);

    // update the 2nd record in the store:
    var rec = myStore.getAt(1);

    // set the value (shows dirty flag):
    rec.set('firstname', 'Betty');

    // commit the change (removes dirty flag):
    rec.commit();

    // update the record in the store, bypass setting dirty flag,
    // and do not store the change in the modified records
    rec.data['firstname'] = 'Wilma'; // updates record, but not the view
    rec.commit(); // updates the view
Notes: If the store has a writer and `autoSave=true`, each set() will execute an XHR to the server. Use `beginEdit` to prevent the store's `update` event firing while using set(). Use `endEdit` to have the store's `update` event fire. Parameters: `name` : String The name of the field to set. `value` : String/Object/Array The value to set the field to. Returns: void | Record

## Public Events

This class has no public events.