0
votes

As a simple example, suppose I want to make a grid of mathematical products:

A | B | C
----------
7 | 2 | 14
1 | 5 | 5
2 | 4 | 8
6 | 0 | 0
3 | 3 | 9
   ...

Suppose my database only stores values for A and B. I then have 3 options:

  1. Calculate C server-side, and use ExtJS models with A, B, C as fields
  2. Calculate C client-side when initialing loading a record (via some reader?) HOW TO DO THIS
  3. Calculate C client-side, after the grid has rendered, by going row-by-row, extracting A and B and setting the value of C
  4. Just store A, B, C in the database

Thoughts? I don't know why, but I think (2) is the cleanest if I can find a way of doing it..

1

1 Answers

1
votes

2 and 3 are both well supported.

For 3 you can use renderer config on the column - lots and lots of examples out there.

For 2 you can map this right in the model as a calculated field via the convert function

Example from docs:

function fullName(v, record){
    return record.data.last + ', ' + record.data.first;
}

function location(v, record){
    return !record.data.city ? '' : (record.data.city + ', ' + record.data.state);
}

Ext.define('Dude', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'fullname',  convert: fullName},
        {name: 'firstname', mapping: 'name.first'},
        {name: 'lastname',  mapping: 'name.last'},
        {name: 'city', defaultValue: 'homeless'},
        'state',
        {name: 'location',  convert: location}
    ]
});