Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.gwtext.client.data
Class ArrayReader

    java.lang.Object
      com.gwtext.client.core.JsObject
          com.gwtext.client.data.Reader
              com.gwtext.client.data.ArrayReader

    public class ArrayReader

extends Reader

Data reader class that is setup to consume data from an array data source. This class sets up the field metadata for the data present in the array data source.

     Object[][] data = new Object[][]{
                    new Object[]{"3m Co", new Double(71.72), new Double(0.02), new Double(0.03), "9/1 12:00am", 1},
                    new Object[]{"Alcoa Inc", new Double(29.01), new Double(0.42), new Double(1.47), "9/1 12:00am", 2}};
     ArrayReader reader = new ArrayReader(new RecordDef(
       new FieldDef[]{
         new StringFieldDef("company"),
         new FloatFieldDef("price"),
         new FloatFieldDef("change"),
         new FloatFieldDef("pctChange"),
         new DateFieldDef("lastChanged", "n/j h:ia")
         }
      ));

If the data array has data that doesn't exactly match the the fields you need in the Reader, then you can specify a (zero based) positional mapper in the field definitions.

     ArrayReader reader = new ArrayReader(new RecordDef(
       new FieldDef[]{
         new StringFieldDef("company"),   //equivalent to new StringField("company", 0);
         new FloatFieldDef("change", 2),
         new DateFieldDef("lastChanged", "n/j h:ia", 4)
         }
      ));

     MemoryProxy dataProxy = new MemoryProxy(data);
     Store store = new Store(dataProxy, reader);
     store.load();

Sometimes you might want to map a field in the data source to be the "ID" of the record. You indicate the position of the data element that represents the ID by using constructor that takes the field ID index as the first argument.

     ArrayReader reader = new ArrayReader(5, new RecordDef(
       new FieldDef[]{
         new StringFieldDef("company"),   //equivalent to new StringFieldDef("company", 0);
         new FloatFieldDef("change", 2),
         new DateFieldDef("lastChanged", "n/j h:ia", 4)
         }
      ));

So for the above data set the ID for the first record will get mapped to 1 (data index of 5 corresponts to the last element in the array) and the ID of the second row gets mapped to 2. Mapping ID's for Record's are useful when, say, the data soource is mapped to a widget like a Grid and when the user clicks on a row, you want to geta handle of the ID for that record which might correspond to the primary key of the database table from which the data is being read.

Since:
  0.9
See Also:
  `RecordDef`

Field Summary

Fields inherited from class com.gwtext.client.data.Reader
`configJS, recordDef`

Fields inherited from class com.gwtext.client.core.JsObject
`jsObj`

Constructor Summary
`ArrayReader(int id, RecordDef recordDef)` Construct an ArrayRader using the specified `RecordDef`.
`ArrayReader(RecordDef recordDef)` Construct an ArrayRader using the specified `RecordDef`.

Method Summary
`protected com.google.gwt.core.client.JavaScriptObject` | `create(com.google.gwt.core.client.JavaScriptObject config, com.google.gwt.core.client.JavaScriptObject recordDef)`
`void` | `setId(int id)` The position of the ID of the field in the underlying array data that provides an ID for the Record

Methods inherited from class com.gwtext.client.data.Reader
`getJsObj, getRecordDef, setRecordDef`

Methods inherited from class com.gwtext.client.core.JsObject
`getProperties, isCreated, setJsObj`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ArrayReader

    public ArrayReader(RecordDef recordDef)

  Construct an ArrayRader using the specified `RecordDef`.

  Parameters:
    `recordDef` - the record definition

### ArrayReader

    public ArrayReader(int id,
                       RecordDef recordDef)

  Construct an ArrayRader using the specified `RecordDef`.

  Parameters:
    `id` - position of the ID of the field in the underlying array data that provides an ID for the Record
    `recordDef` - the record definition
  See Also:
    `Record`

Method Detail

### create

    protected com.google.gwt.core.client.JavaScriptObject create(com.google.gwt.core.client.JavaScriptObject config,
                                                                 com.google.gwt.core.client.JavaScriptObject recordDef)

  Overrides:
    `create` in class `Reader`

### setId

    public void setId(int id)

  The position of the ID of the field in the underlying array data that provides an ID for the Record

  Parameters:
    `id` - the ID

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD