Issues with ExtJS Ajax for the grid

I have a grid panel in my code like:

Ext.create('Ext.grid.Panel', {
        id : 'frPanel-' + interfaceId,
        store : frStore,
        columns : [
                {
                    text : 'Sequence',
                    dataIndex : 'ruleId',
                    menuDisabled : true
                },
                {
                    text : 'Source',
                    dataIndex : 'source',
                    renderer : function(value, metaData) {
                        var newValue = convertObjValue(value);
                        if (newValue.match(/[-]+/i)) {
                            metaData.tdAttr = 'data-qtip="'
                                    + networkStore(value) + '"';
                        }
                        return newValue;
                    }
                },
// paging bar at the bottom
        dockedItems : [ {
            xtype : 'pagingtoolbar',
            store : frStore, // same store GridPanel is using
            dock : 'bottom',
            displayInfo : true
        } ],
height : 300,
        width : '100%',
        forceFit : true,
        renderTo : 'frContainer-' + interfaceId
    });

And this is an auxiliary function i:

// To get the value after 2nd colon for object and object-group
function convertObjValue(value) {
    var result;
    var exp = /.*?:.*?:(.*)/i;
    var newValue = value;

    if ((result = exp.exec(value)) != null) {
        if (result.index === exp.lastIndex) {
            exp.lastIndex++;
        }
        newValue = result[1];
    }
    return newValue;
}

Score:

function networkStore(value) {

//var store = Ext.create('Ext.data.Store', {
var store = new Ext.data.Store({
    model : 'networkModel',
    autoLoad : {
        timeout : 60000
    },
    proxy : {
        type : 'ajax',
        url : networkObjsURL + "&" + Ext.urlEncode({
            'peId' : value
        }),
        reader : {
            type : 'json',
            idProperty : 'objValue'
        },
     }
});
var hoverOutput = "";

if(store.data.length > 0){
store.data.items.forEach(function(item) {
    hoverOutput += item.data.objectValue + "</br>";
});
}
console.log(hoverOutput);
return hoverOutput;

and the last, but no less important model:

Ext.define('networkModel', {
    extend : 'Ext.data.Model',
    fields : [ {
        name : 'objectValue'
    } ]
});

Now a problem arises. The problem is that I do not put a breakpoint in the browser in the repository, the values ​​do not appear in qtip. I assume this is due to the fact that the grid panel is not waiting for a response from the store after an ajax response. Can someone help me figure out a workaround for this situation?

Thanks in advance

+4
source share
2 answers

Did you try to install

autoLoad:false 

and then something like:

store.load({
    callback: function(records, operation, success) {
        if (success == true) {
            //do your stuff
            var hoverOutput = "";

            if(store.data.length > 0){
            store.data.items.forEach(function(item) {
                hoverOutput += item.data.objectValue + "</br>";
            });
            }
            console.log(hoverOutput);
            return hoverOutput;
        } else {
            // the store didn't load, deal with it
        }
    }
    // scope: this,
});

, , , , . Ext , ajax . , , ajax. Ext, , , . , , , , .

, , .. , , , .

+1

, ExtJS , , , ExtJS 5.

. render ( networkStore) ?

, , / ( API /). , frStore ( ). convert / render.

, ().

ExtJS , , qtip.

, networkStore (autoload: true), , , , remoteFilter .

frStore , frStore FrModel .

Ext.define('FrModel', {
  extend: 'Ext.data.Model',
  // ...
  fields: [
    // source field
    // ...
    /** qtip value **/
    {
      name: 'qtip',
      type: 'string',
      convert: function (value, record) {
        var result = '';
        // below code is from your render function with modifications
        if (record.get('rendered_source').match(/[-]+/i)) {
          result = 'data-qtip="'
             + networkStore(record.get('source')) + '"';
        }
        return result;
      },
      depends: ['source', 'rendered_source']
    },
    /** rendered source **/
    {
      name: 'rendered_source',
      type: 'string',
      convert: function (value, record) {
        var newValue = convertObjValue(record.get('source'));
        return newValue;
      },
      depends: ['source']
    }
  ]
  // ...
}

render :

// ...
{
  text : 'Source',
  dataIndex : 'rendered_source', // this will allow users to sort & filter this field by the values which are displayed
  renderer : function(value, metaData, record) {
      metaData.tdAttr = 'data-qtip="'
        + record.get('qtip') + '"';
    }
    return value;
  }
},
// ...

networkStore, : ( / , )

Ext.create('Ext.data.Store', { // using Ext.create is better
    model : 'networkModel',
    storeId: 'networkStore', // registering store in  Ext.data.StoreManager in order to get later this store by Ext.getStore(<store_id>)
    autoLoad : true,
    proxy : {
        type : 'ajax',
        url : networkObjsURL, // we load all records but I mentioned earlier that you can change this
        reader : {
            type : 'json',
            idProperty : 'objValue'
        },
     }
});

peId netowrkModel, .

Ext.define('networkModel', {
    extend : 'Ext.data.Model',
    fields : [
      {
        name: 'objectValue'
      },
      {
        name: 'peId',
        type: 'int'
      }
    ]
});

- networkStore:

function networkStore(value) {
  var store = Ext.getStore('networkStore');
  var records = store.query('peId', value, false, true, true);
  var hoverOutput = "";

  if (records.length > 0) {
    records.each(function(item) {
      hoverOutput += item.get('objectValue') + "</br>";
    });
  }

  console.log(hoverOutput);
  return hoverOutput;
}

PS. .

IMO . .

, , , .

FrModel NetworkModel peId, networkStore qtip convert .

0

All Articles