I have a grid in that one column has editor of type combo. This combo fills dynamically. Right now i can show only one column in its drop down list but i want to show more than one column in its drop down list. each drop down list may contain different column names.
I succeed in creating tpl string but fail to assign this tpl to combo.
My logic is:
create grid
in focus event- fill combo dynamically and create tpl
assign tpl to combo
show drop down list by expand method.
Please suggest me if there is any method like combo.setTpl(tpl_string)
Logic Description:
1. Created model which will hold two columns
i. column_name: Name of column from data base.
ii. data_type: Data type of column
Ext.define('modelTableStructure',
{
extend: 'Ext.data.Model',
fields:
[
{ name: 'column_name', type: 'string' },
{ name: 'data_type', type: 'string' }
]
});
2. Created store which will use model in step 1
var storeTableStructure = Ext.create('Ext.data.Store',
{
model: 'modelTableStructure',
autoLoad: false,
proxy: new Ext.data.HttpProxy
({
type: 'ajax',
reader:
{
type: 'json',
root: 'rows',
idProperty: 'column_name'
}
}),
listeners:
{
load: onLoadStore
}
});
3. This is to change data type of columns as per EXT JS
var type_lookup = new Object;
type_lookup['int'] = 'numberfield';
type_lookup['float'] = 'numberfield';
type_lookup['string'] = 'textfield';
type_lookup['date'] = 'datefield';
type_lookup['boolean'] = 'checkbox';
type_lookup['varchar'] = 'textfield';
type_lookup['bit'] = 'checkbox';
4. This is a model and store of a combo
Ext.define('modelTableData',
{
extend: 'Ext.data.Model'
});
var storeDataID = new Ext.data.JsonStore
({
model: 'modelTableData',
autoLoad: false,
proxy: new Ext.data.HttpProxy
({
type: 'ajax',
url: 'url to get data',
reader:
{
type: 'json',
root: 'rows',
idProperty: 'primary key column name'
}
})
});
5. Here is the method which will get called on store load which we created in step 2
function onLoadStore() {
var cnt = storeTableStructure.getCount();
fields = [];
var colNames = [];
for (var i = 0; i < cnt; i++) {
var Col_nm = storeTableStructure.getAt(i).data.column_name;
var Col_Type = storeTableStructure.getAt(i).data.data_type;
colNames[i] = Col_nm;
fields[i] = {
name: Col_nm,
type: Col_Type,
editor:
{
xtype: type_lookup[Col_Type]
}
};
}
DataID_createHeaderTPL(colNames);
modelTableData.setFields(fields, 'COL_PK_ID', 'COL_PK_ID');
var proxy = new Ext.data.HttpProxy
({
type: 'ajax',
url: 'TestCase.ashx?methodname=getdataids&stepdisplayname=name',
reader:
{
type: 'json',
root: 'rows',
idProperty: 'COL_PK_ID'
}// reader end
}); // proxy end
proxy.setModel(modelTableData, true)
storeDataID.setProxy(proxy);
storeDataID.load({
url: 'TestCase.ashx?methodname=getdataids&stepdisplayname=name'
});
};
var tplDataid = '';
function DataID_createHeaderTPL(colNames) {
var hd = '';
var td = '';
for (var i_f = 0; i_f < colNames.length; i_f++) {
hd = hd + '<th width=100> ' + colNames[i_f] + ' </th>';
td = td + '<td width=100> {' + colNames[i_f] + '} </td>';
}
tplDataid = '<tpl>' +
'<table width=500>' +
'<tr style="text-align: left;">' +
hd +
'</tr>' +
'</table>' +
'</tpl>' +
'<tpl for=".">' +
'<div class="x-boundlist-item">' +
'<table width=500>' +
'<tr>' +
td +
'</tr>' +
'</table>' +
'</div>' +
'</tpl>';
}
6. This function is creating my grid.
function showRecordDetails() {
storeTableStructure.load({
url: 'TestCase.ashx?methodname=gettablestructure&stepdisplayname=name'
});
Ext.define('gridTCStep',
{
extend: 'Ext.grid.Panel',
alias: 'widget.gridTCStep',
requires:
[
'Ext.grid.plugin.CellEditing',
'Ext.form.field.Text',
'Ext.toolbar.TextItem'
],
initComponent: function() {
this.editing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
Ext.apply(this,
{
store: StoreTCStep,
width: 980,
height: 340,
plugins: [this.editing],
columns:
[
{
id: "DATA_ID",
header: "Data ID",
minWidth: 50,
dataIndex: 'DATA_ID',
flex: 3,
editor:
{
xtype: 'combo',
allowBlank: false,
forceSelection: true,
store: storeDataID,
hideTrigger: true,
displayField: 'Data_ID',
valueField: 'Data_ID',
enableKeyEvents: true,
matchFieldWidth: false,
listeners:
{
'focus': DataID_Focus,
'keypress': combo_KeyPress
},
tpl: Ext.create('Ext.XTemplate', tplDataid),
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{Data_ID}',
'</tpl>'
)
}
}
]
});
this.callParent();
}
});
button = Ext.get('btnNewEntry');
var lblWd = 90;
var formPanel = new Ext.form.FormPanel
({
bodyStyle: 'padding:5px 5px 5px 5px',
submitEmptyText: true,
items:
[
{
xtype: 'panel',
name: 'gridpanel',
shadow: false,
items:
[
{
id: 'griddata',
items: gridTCStep,
store: StoreTCStep
}
]
}
]
});
win = Ext.create('widget.window',
{
closable: true,
frame: false,
closeAction: 'destroy',
width: 1000,
minWidth: 350,
height: 600,
shadow: false,
resizable: false,
draggable: false,
items:
[
{
id: 'westpanel',
name: 'westpanel',
items: formPanel
}
]
});
win.show();
};
7. On focus event of combo i am calling this function. In this function i loaded store created in step 2. so that combo will filled by new record and as per new records it will have multiple columns. You can see tpl is created in store load event.
function DataID_Focus(combo, records, eOpts) {
storeTableStructure.load({
url: 'TestCase.ashx?methodname=gettablestructure&stepdisplayname=name'
});
combo.tpl = Ext.create('Ext.XTemplate', tplDataid);
combo.expand();
};