I know this has been asked somewhere again and again but I can't find a solid answer as standard for this kind of problem.
As many have done before I have an editor inside a grid that is a combobox that uses remote store from a database. Now suppose that there is a table in the database with 50,000 records.
The combobox only loads the first 15. When I select a record between these 15 everything displays fine. To render the displayField
instead the valueField
, I use the following function
renderCombobox : function(value, metaData, record, rowIndex, colIndex, store, view, isNewRow){
var me = this,
columns = me.columns,
editor, editorStore, editorIndex, displayField, display, rec;
for(var i=0,j=columns.length;i<j;i++){
if(columns[i].getEditor){
editor = columns[i].getEditor(record);
if(editor.xtype === 'combobox'){
editorStore = editor.getStore().load();
editorIndex = editorStore.findExact(editor.valueField, value);
displayField = editor.displayField;
}
}
}
if(editorIndex != -1){
rec = editorStore.getAt(editorIndex);
if(rec && rec.get(displayField)){
display = rec.get(displayField);
}
}
return display;
}
The problem is the following scenario.
If I type ahead, I can find a record that is not between these 15 records. For example the record 42,300. I select it and for the moment everything is OK.
Now If I click on another field on another editor in the grid (i.e. datefield) the renderer
function for the combobox returns undefined
as it tries to find the record with value of the record 42,300 that does not exist in the store. Debugger says that the store contains again only the first 15 records.
Is there any configuration I miss? The store needs a limitation. I can't bring 50,000 records from the database at once.
this.store.on({beforeload:somefns,load:somefns})
. These two functions should be responsible to find the last value of the combobox that came from the database and insert it in the store withstore.insert(0,record)
. So every time the first record will be that of the remote source. I'll have a try later this evening and come back in case I have a solution. This might be useful to someone else. – dev