Note that there are some explanatory texts on larger screens.

plurals
  1. POGrid with json store sometimes don't show data
    primarykey
    data
    text
    <p>I have a extjs 4 grid panel with remote stores. On the renderer of column there is function, which change ID to NAME. Mostly times it works fine, but sometimes (~40%) the grid shows with empty columns. I've tried to debug - the store is defined, but its items are empty. To my mind store not loaded yet, or already destroyed (if it is possible).</p> <p>How to correctly show grid, with full data?</p> <p>There is my simplified code:</p> <h2>Loading needed components</h2> <pre><code>Ext.Loader.setConfig({ enabled:true }); Ext.Loader.setPath('Ext.ux', '/js/ux'); Ext.require([ 'Ext.grid.*', 'Ext.data.*' ]); Ext.onReady(function () { </code></pre> <h2>Create models</h2> <pre><code> Ext.define('Expense', { extend:'Ext.data.Model', fields:[ {name:'id', type:'number'}, {name:'cost_id', type:'string'}, {name:'comment', type:'string'} ] }); Ext.define('Cost', { extend:'Ext.data.Model', fields:[ {name:'id', type:'string'}, {name:'name', type:'string'}, {name:'displayname', type:'string'} ] }); </code></pre> <h2> Create stores</h2> <pre><code> store = Ext.create('Ext.data.Store', { autoDestroy:true, model:'Expense', autoLoad:true, autoSync:true, pageSize:30, proxy:{ type:'ajax', url:'/expenses/gettable', reader:{ type:'json', root:'data', record:'Expense' }, writer:{ type:'json' }, api:{ create:'/expenses/create', update:'/expenses/update', destroy:'/expenses/delete' } } }); costsStore = Ext.create('Ext.data.Store', { autoDestroy:true, model:'Cost', autoLoad:true, autoSync:true, proxy:{ type:'ajax', url:'/costs/gettable', reader:{ type:'json', record:'Cost' }, writer:{ type:'json', allowSingle:false }, api:{ create:'/costs/create', update:'/costs/update' } } }); </code></pre> <h2> Configure grid panel</h2> <pre><code> grid = Ext.create('Ext.grid.Panel', { store:store, autoSync:true, columns:[ { id:'comment', header:'Задача', dataIndex:'comment', flex:5 }, { id:'cost', header:'Cost', dataIndex:'cost_id', flex:5, editor:{ xtype:'combobox', store:costsStore, valueField:'id', displayField:'name', name:'cost_id' }, renderer:function (value, meta, record) { if (value != '') { ind = costsStore.find('id', value); elem = costsStore.getAt(ind); if (elem) { return elem.data['name']; } } } } ], renderTo:'editor-grid' }); }); </code></pre> <p>I've tried to manually load stores on grid render event:</p> <pre><code>grid = Ext.create('Ext.grid.Panel', { listeners:{ beforerender:function(){ store.load(); costsStore.load(); } } ... }); </code></pre> <p>It is decrease empty table to ~10% cases, but not 0%...</p> <p>The only way I've found is to set delay after loading all stores, and then show grid, something like this:</p> <pre><code>listeners:{ 'load':function(){ window.setTimeout("getGrid()", 1000); } } </code></pre> <p>Where getGrid() is the function with creating grid.panel.</p> <p>What I have to do, to show grid only after all stores loaded, or show error if data can't load?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload