How to change combobox store data in ExtJS 4.1 - extjs

I define a combobox like this
{
xtype: 'combobox',
emptyText: 'Functions'
store: [ 'none' ]
}
then, on some event the store should load new data, so I get the store from the combobox and try this:
oFunctionStore.loadData( ['dothis', 'dothat', 'dosomething' ] );
but after this, the combobox has a dropdown without any visible content, just tiny blank lines.

// Change this...
oFunctionStore.loadData( ['dothis', 'dothat', 'dosomething' ] );
// to this...
oFunctionStore.loadData( [ [ 'dothis' ], [ 'dothat' ], [ 'dosomething' ] ] );
The combobox implicitly creates an Ext.data.ArrayStore, which will convert arrays into models.
The data parameter passed to
loadData is expected to be either an array of models, or an
array of objects than can be converted to models (in this case, an
array of arrays).
On the initial store load, the original array was converted to [ [ 'none' ] ] behind the scenes.
See an example here

carStore - any store for main combo.
carModelStore - store, which should be depended on selection in the carStore - based combo box
var carModelStore = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['id', 'car-model'],
root: 'rows'
}),
storeId: 'car-model-store',
proxy: new Ext.data.HttpProxy({
url: 'carmodeldataprovider.json?car-name=lamborghini'
}),
autoLoad: true
});
{ xtype: 'combo', name: 'car-name', fieldLabel: 'Car', mode: 'local', store: carStore, triggerAction: 'all',
listeners: {
select: function(combo, records, eOpts){
var carName = records.get('car-name'); // the element selected in combo
var carModelStore = Ext.StoreMgr.lookup("car-model-store");
carModelStore.proxy.setUrl('carmodeldataprovider.json?car-name=' + carName, false);
carModelStore.reload();
}
}
}

Related

Grid RowEditing - Update not working

Rowediting is not working on update. I have grid with column in it. If i add a new row then data will bind as we change.
If we try to change the binded data then after update it will not reflect the changed one.
Here is my Grid combo box
xtype: 'grid',
itemId: 'gdItemId',
store: {
type: 'webapi',
api: {
read: 'api/Report/GetTimeDetails'
},
autoLoad: false,
},
columns: [
{
text: 'Type', dataIndex: 'type_id', width: '12%', editor: combo, renderer: comboBoxRenderer(combo),msgTarget: 'side'
}
var store = new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
[1, "Deliverys"],
[2, "Pickup"]
]
});
var comboBoxRenderer = function (combo) {
return function (value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField));
};
}
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
What i am doing wrong here ?
I found some problems here one is , I think has no model defined the model is necessary for use as base in your CRUD, another thing is there no proxy type webapi should be type: 'rest' if you wanna use RESTFULL [ , finally autoSync should be true for update data and another problem you should map the update method for send data to your server api{ read : yourlinkread , update: yourlinktoupdate }
Complete Example
https://docs.sencha.com/extjs/4.2.3/#!/example/build/KitchenSink/ext-theme-neptune/#cell-editing

Dynamic store model grid columns

The grid looks to have the right number of rows displayed and the column headers are correct but the actual data in the cells is blank. Any idea why this is happening?
data
var data = new DOMParser().parseFromString('<sio><sql><row><Name>item 1</Name><Dn>value 1</Dn></row><row><Name>item 2</Name><Dn>value 2</Dn></row></sql></sio>',"text/xml");
var columns=JSON.parse('[{"dataIndex": "Name","text": "NEW Clumn Name"},{"dataIndex": "Dn","text": "NEW Column Dn"}]');
var fields = JSON.parse('[{"name": "Name","type": "string"},{"name": "Dn","type": "string"}]');
model
var model = new Ext.data.Model({
fields: fields
});
new model
Ext.define('testModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.String',
],
fields: fields
});
store
var store = new Ext.data.Store({
// model: model, // this not works
model: 'testModel', // this works
// fields: fields, // this works
proxy: {
type: 'memory',
reader: {
type: 'xml',
rootProperty: 'sql',
record: 'row'
}
}
});
grid
var grid = new Ext.grid.GridPanel({
xtype: 'gridpanel',
title: 'Test',
titleAlign: 'center',
columnLines: true,
id: 'testGrid',
forceFit: true,
store: store,
});
load
grid.reconfigure(store,columns);
store.loadRawData(data);
console.log(fields);
log $reference: undefined - any idea what that means
[Object, Object]
0: Object
$reference: undefined
name: "Name"
type: "string"

How can I preserve the selections in an ExtJS grid with filtered data?

I'm using ExtJS 4.1.2, and I have an Ext.grid.Panel with a check-box selection model and a text-box in the header for filtering the items in the grid:
var nameStore = new Ext.data.Store({
...
proxy: { type: 'ajax' ... },
fields: [ { name: 'name', type: 'string' }, ... ],
});
var headerBar = new Ext.toolbar.Toolbar({
xtype: 'toolbar',
dock: 'top',
layout: 'fit',
items: [{
xtype: 'textfield',
...,
listeners: {
change: function(fld, newVal, oldVal, opts) {
var grid = ...;
if (newVal.length > 0)
grid.store.filterBy(function(record, id) { return record.get('name').indexOf(newVal) !== -1; });
else
grid.store.clearFilter()
}
}
}]
});
var nameGrid = new Ext.grid.Panel({
...
selType: 'checkboxmodel',
selModel: { mode: 'SIMPLE' },
store: nameStore,
columns: [ { dataIndex: 'name', flex: true }, ... ],
dockedItems: [ headerBar ],
bbar: [ { xtype: 'tbtext', text: '0 items selected' ... },
listeners: {
selectionchange: function(selModel, selected, opts) {
var txt = ...;
txt.setText(Ext.String.format("{0} items selected", selected.length));
}
}
});
As shown nameStore's filter is applied (or removed) based on the value in headerBar's textbox. Also, a text string in the bottom bar is updated as items are selected/deselected.
Each of these features is working smoothly on its own. But the interaction is giving me trouble: if an item is selected and then gets filtered out, it is deselected and then remains so when the filter is cleared.
How can I maintain the selections (or at least appear to do so to the user) of "hidden" items, either for use elsewhere in my application or to reselect when the filter is cleared? Thanks!
you need not to add the selected grid separately. This can be done in one grid only. Simple method is to have an array variable in page scope and capture the grid select event or itemclick event whatever you want.
e.g if you use select event it will give you your record.
select( this, record, index, eOpts )
you can get your record id and push it to the array variable that you declared.
Once you filtered out the grid. you can loop through the filtered records and call select method by getting selection model.
e.g
grid.getSelectionModel().select(record);
Hope this will help.

Extjs Combo - Why combo is loading while I have not created form include combo

I define a window include a form and some field and combo box. Example like
Ext.define('Ext.example.ABC', {
extend: 'Ext.window.Window',
items:{
xtype:'form',
items:[
{
xtype: 'combo',
id: 'example',
name: 'ax',
triggerAction: 'all',
forceSelection: true,
editable: false,
allowBlank: false,
fieldLabel: 'example',
mode: 'remote',
displayField:'name',
valueField: 'id',
store: Ext.create('Ext.data.Store', {
fields: [
{name: 'id'},
{name: 'name'}
],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'example.php',
reader: {
type: 'json',
root: 'rows'
}
}
}
})
}]
}
,load: function(a) {
// do some thing
}
});
And I have a button in a grid panel
tbar:[
{
text:'create',
handler:function(){
var x = new Ext.example.ABC();
x.load(0);
}
}
But Why when i just start gridpanel then combo also load while I have not click button create.
I have many combo box and that make my grid panel load slowly :(
How can i fix that thanks
I guess you need set autoLoad: false config option for your combobox's store.
In relation to your comments - I've created an example. You can check it on jsFiddle.
It was created on ExtJs 3.4, but I think for 4.x it will be not very different.
var arrTestData = [
['AL', 'Alabama', 'The Heart of Dixie'],
['AK', 'Alaska', 'The Land of the Midnight Sun'],
['AZ', 'Arizona', 'The Grand Canyon State'],
['AR', 'Arkansas', 'The Natural State'],
['CA', 'California', 'The Golden State']
];
var combosCount = 5;
var arrItems = [];
for (var i = 0; i < combosCount; i++) {
var comboId = Ext.id();
// simple array store
var store = new Ext.data.ArrayStore({
parentCombo: comboId,
fields: ['abbr', 'state', 'nick'],
data : []
});
store.on('load', function() {
var combo = Ext.getCmp(this.parentCombo);
combo.setValue(combo.defaultValue);
});
var combo = new Ext.form.ComboBox({
id: comboId,
fieldLabel: 'Combobox #' + (i + 1),
store: store,
displayField:'state',
valueField:'abbr',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText:'Select a state...',
defaultValue: arrTestData[i][0],
selectOnFocus:true
});
arrItems.push(combo);
}
var formPanel = new Ext.form.FormPanel({
bodyStyle: 'padding:5px;',
items: arrItems,
renderTo: 'combos-container'
});
new Ext.Button({
text: 'Do all cool things',
renderTo: 'combos-btn',
handler: function() {
var arrCombos = formPanel.findByType('combo');
Ext.each(arrCombos, function(combo){
combo.getStore().loadData(arrTestData);
});
}
});
So what we do there:
1. For each store we'll save parent combobox id - this is required to identify related combobox.
2. For each combobox we save own parameter - defaultValue. This is the value we want set as default after store will be loaded.
3. Listen for 'load' event and set default value for the combo.
I hope this is what you was waiting for :)
Have autoLoad:false and load your store manually for default values.
When you really want to load the store, you can do
store.load()
which will load your store for default values.

How to render combobox dropdownlist

I am having trouble filtering an array store.
Situation
I have 2 comboboxes with an array store. combobox 1 and combobox 2, both are in mode 'local' and have a predefined array store. when i click and select a row in the first combobox, I apply a filter on the second combobox (which was not yet cliked upon). The thing is that the second combobox did not render it's data (or html) yet so the filter wasn't applied.
when i click on the second combobox, and then clicking on the first, the filter is applied and working.
my question is, how to pre-render an array_store/combobox?
I did try to expand the combobox first, but also didn't work for me. (see commented code)
var store1 = new Ext.data.ArrayStore({
fields: ['id','name'],
data:somedata //array of some data
});
var store2 = new Ext.data.ArrayStore({
fields: ['id','name'],
data:somedata //array of some data
});
var combobox1 = {
name: 'combobox_1',
xtype: 'combo',
hiddenName: 'combobox_1',
store: store1,
displayField:'name',
valueField:'id',
mode:'local',
triggerAction: 'all',
allowBlank:true,
emptyText:'Select...',
listeners:{
select: function(st, r){
var selected = r.get('name');
var combobox2 = Ext.getCmp('combobox2');
//combobox2.expand();
combobox2.store.filter([
{
property : 'name',
value : selected,
anyMatch : true,
caseSensitive: false
}
]);
},
scope:this
}
}
var combobox2 = {
name: 'combobox_2',
xtype: 'combo',
hiddenName: 'combobox_2',
store: store2,
id: 'combobox2'
displayField:'name',
valueField:'id',
mode:'local',
triggerAction: 'all',
allowBlank:true,
emptyText:'Select...',
}

Resources