1. #1
    Sencha User
    Join Date
    Apr 2012
    Location
    Billerica, MA
    Posts
    60
    Vote Rating
    9
    jattardi will become famous soon enough

      1  

    Default Unanswered: Value of converted field not updating on refresh

    Unanswered: Value of converted field not updating on refresh


    Hi all!

    I have a List backed by a Store, with the PullRefresh plugin. One of the fields in my Model is a calculated field. It represents the average of two other fields. (This is for showing disk I/O performance. readOpCountAvgPerSec is the average number of read operations, writeOpCountAvgPerSec is the number of write operations. In the list, I am showing just an average between the two).

    Code:
          
    { 
        name: 'opCountAvgPerSec', 
        type: 'int',
        convert: function(value, record) {
            return ((record.get('readOpCountAvgPerSec') + record.get('writeOpCountAvgPerSec')) / 2;
        } 
    }
    However, when I refresh the list, the value of this calculated field doesn't change. I noticed this during testing. The values for 'readOpCountAvgPerSec' and 'writeOpCountAvgPerSec' both dropped to zero (after being nonzero), but the calculated 'opCountAvgPerSec' field still had the old, nonzero average.

    I set a breakpoint in the convert function and restarted my app. The convert function gets called when the Store is first loaded, as expected, but never gets called again. I tried doing a pull-to-refresh and also explicitly going in my console and calling Ext.getStore('DiskPerformance').load(), but neither case triggered my breakpoint.

    Is there something else I need to do to make the function be called to re-calculate with new data?

    Thanks! Looking forward to SenchaCon!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Answers
    3549
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You need to set opCountAvgPerSec field as an empty string or something to trigger the convert method to be fired.

    Code:
    record.set({
        readOpCountAvgPerSec : 1,
        writeOpCountAvgPerSec : 2,
        opCountAvgPerSec : '' //triggers the convert
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Billerica, MA
    Posts
    60
    Vote Rating
    9
    jattardi will become famous soon enough

      1  

    Default


    Where would be the appropriate place to do this if I need this field updated on every refresh?
    Add a listener to the load event on the Store, then iterate over all items and set the field blank to force the update?

  4. #4
    Sencha User
    Join Date
    Aug 2012
    Location
    Vancouver, Canada
    Posts
    31
    Answers
    1
    Vote Rating
    1
    trevorcox is on a distinguished road

      0  

    Default


    Thanks, this is pretty critical info for anyone trying to use 'convert'; I've added this comment to the docs.

  5. #5
    Sencha User
    Join Date
    Nov 2013
    Posts
    244
    Answers
    4
    Vote Rating
    -6
    xjscrafter is infamous around these parts

      0  

    Default


    My computed column is not updating, and when I set the field to 0 to trigger the convert function nothing happens, the value of 0 just ends up in the column.

  6. #6
    Sencha User
    Join Date
    Mar 2010
    Posts
    491
    Answers
    12
    Vote Rating
    1
    abcdef is on a distinguished road

      0  

    Default


    Quote Originally Posted by trevorcox View Post
    Thanks, this is pretty critical info for anyone trying to use 'convert'; I've added this comment to the docs.
    I couldn't find this in the docs. How does this need to be handled, so that when the list refreshes, the convert field does a fresh fetch? Thanks!

  7. #7
    Sencha User
    Join Date
    Mar 2010
    Posts
    491
    Answers
    12
    Vote Rating
    1
    abcdef is on a distinguished road

      0  

    Default


    Quote Originally Posted by jattardi View Post
    Where would be the appropriate place to do this if I need this field updated on every refresh?
    Add a listener to the load event on the Store, then iterate over all items and set the field blank to force the update?
    Did you figure out an appropriate place to do this? Thanks!

  8. #8
    Sencha User
    Join Date
    Mar 2013
    Posts
    4
    Vote Rating
    0
    psiegers is on a distinguished road

      0  

    Default


    I am facing the same problem... is this important issue ever going to be adressed?