0

I'm trying to implement a custom renderer which manages two fields from a grid - for the first field a simple string is returned, and for the second I query the database:

...

columns: [{
                dataIndex: 'id',
                width: 50,
                text: 'ID',
                field: {
                    type: 'textfield',
                    allowBlank: false
                },
                renderer: function(value, metaData, record, row, col, store, gridView){

                    return DirectTest.app.getController("PersonalInfo").renderUsername(value, record, col);

                  }
            }, {
                dataIndex: 'username',
                flex: 1,
                text: 'Username',
                field: {
                    type: 'textfield',
                    allowBlank: false
                },
                renderer: function(value, metaData, record, row, col, store, gridView){

                    return DirectTest.app.getController("PersonalInfo").renderUsername(value, record, col);

                  }
            }
...

The problem is that within the renderer function, I'm calling an Ext.Direct method (which is asynchronous). I've tried both promises and callbacks and ended up with this ugly code (just wrapped all the conditions in the Ext.Direct callback), which doesn't work - it does not return the values:

renderUsername: function(value, record, col){

        var col = col;
        return QueryDatabase.getResults({page: 1, start: 0, limit: 25}, function(provider, response){
            console.log(response.result[0]);
            console.log("col = "+col);
            switch(col){
                case 0:
                    return "Lilly is a fluffy cat";
                    break;

                case 1:
                    return response.result[0].username;
                    break;
                }

        });

    }

What should I do? What is the most elegant solution?

Hello Lili
  • 1,527
  • 1
  • 25
  • 50
  • 2
    The renderer config is just so you can transform the value/appearance of that grid cell's data - I don't think you should actually be retrieving data within it. I would just load the grid with a callback function, and in that function I would do all the Ext.Direct stuff and then update the grid/store data. – zeke Dec 10 '18 at 21:42
  • 2
    First if all you cannot use Async data fetch in renderer() because renderer() has to return some value to cell display.Now if you want to get dynamic data according to current value you can either update grid's store after grid loads OR you have to initially fetch required data. – Tejas Dec 12 '18 at 06:51
  • @Tejas this is how I solved the problem. – Hello Lili Dec 12 '18 at 10:50
  • how you solved ? – Tejas Dec 13 '18 at 05:51

0 Answers0