ExtJS RowEditor on Grid - extjs

When my users edits the Grid via RowEditor combo entries and checkboxes are annoying
1 Apple
2 Orange
3 Pear
For instance with the combo above the user will select Orange then update - the Grid now instead of saying orange will display the number 2 - I would like it to show orange when a successful edit has been made.
code for my combo
editor : {
allowBlank : false,
displayField : 'team',
editable : false,
emptyText : 'Select Team',
forceSelection : true,
lazyRender : true,
mode : 'remote',
name : 'team',
store : storeTeam,
triggerAction : 'all',
valueField : 'id',
xtype : 'combo'
}
I think I read that you could send the complete row back to insert or I should listen to the update of the grid and then change the field but I need some guidance on what is best
Cheers

Try the code below. Use this column just like you would any other ExtJS grid column.
Ext.grid.FixedListColumn = Ext.extend(Ext.grid.Column, {
constructor: function(cfg){
cfg.editor = new Ext.form.ComboBox(cfg.editor);
Ext.grid.ComboBoxColumn.superclass.constructor.call(this, cfg);
this.renderer = Ext.util.Format.comboRenderer(cfg.editor);
}
});
Ext.grid.Column.types.fixedlistcolumn = Ext.grid.FixedListColumn;
// Takes in a combobox and returns a renderer that looks up the displayField in
// the store attached to the combo
Ext.util.Format.comboRenderer = function(combo){
return function(value){
var record = combo.findRecord(combo.valueField, value);
return record ? record.get(combo.displayField) : combo.valueNotFoundText;
}
}
// Use this as the 'columns' parameter when creating your Grid
var grid_columns = [
{xtype:'fixedlistcolumn',
store: [[1,'Apple'],[2,'Orange']]},
...
];

I hope this helps...
You can add renderer definition to your team column:
Below is example of how simple true/false values are represented as Yes/No in the GridPanel:
renderer:function(val){
if(val=="true" || val == true) {
return "Yes";
}
else{
return "No";
}
}

Related

how to access class variables from combo select listener- extjs 3.4

I am creating a dependent combo for country,city and state here. I have a select listener in country combo,wherein I call loadCityCombo method.. But, I am not able to access cityStore from loadCityCombo.
What changes should I do for the dependent combo to work?
this.country = {
store : this.countryStore,
xtype: 'combo',
fieldLabel : 'Country',
displayField : 'country',
valueField : 'country',
name : 'country',
typeAhead : true,
mode : 'local',
triggerAction : 'all',
editable : false,
forceSelection : true,
allowBlank : false,
emptyText : 'Select Country',
listeners : {
'select' : this.loadCityCombo
}
};
this.loadCityCombo = function(country) {
console.log('load-CityCombo');
console.log(country);
var ctyCombo = (that.mainFormPanel.getComponent('locationDetailsFieldSet')).getComponent('citycombo');
console.log(ctyCombo);
var that = this;
if(country != null){
var countryName = country.value;
console.log(this.cityStore);
console.log(that.cityStore);
that.cityStore.reload({
params : {
country : countryName,start : 1,limit : 1
}
});
}
};
I think you could be suffering from a scope issue, try adding
listeners : {
'select' : this.loadCityCombo,
scope: this
}
You should be able to use the this keyword and not the 'that' variable you have defined
EDIT
If not defined, this usually refers to the browser window.

Selecting row in child grid selects the row in parent grid with same row index

I have Implemented Nested Grid in Rowexpander Plugin.Now Issue is that when i am selecting any nth row of child grid then parent grid nth row also get selected . I think because both have same rowIndex.Even when i mouseover on the child grid row same mouseover effect display for parent also simultaneously.
Below is the code for Rowexpander
var expander = new Ext.ux.grid.RowExpander({
expandOnDblClick : false,
tpl : new Ext.Template('<div id="NestedGridRow-{id}"></div>'),
renderer: function(v, p, record) {
if (record.get('cmaStatus') == 'G') {
p.cellAttr = 'rowspan="2"';
return '<div class="x-grid3-row-expander"></div>';
}
},
});
expander.on('expand', expandedRow);
function expandedRow(obj, record, body, rowIndex){
//absId parameter for the http request to get the absence details.
//Use Id to give each grid a unique identifier. The Id is used in the row expander tpl.
//and in the grid.render("ID") method.
var row = "NestedGridRow-" + record.get("id");
var id2 = "mygrid-" +record.get("id");
sapid_para = record.get('sapid');
//Create the nested grid.
var gridX = new Ext.grid.GridPanel({
id:'nestedGrid',
store: storenested,
//stripeRows: true,
columns: [
{
header : "CMA Date",
width : 120,
sortable : true,
dataIndex : 'cmaDate',
},
{
header : "Source Model",
width : 120,
sortable : true,
dataIndex : 'sourceModel',
},
{
header : "Remarks",
width : 390,
sortable : true,
dataIndex : 'remarks',
}],
height: 120,
id: id2,
plugins : [editor],
renderTo: row,
stripeRows:true,
listeners: {
render: function(gridX) {
gridX.getView().el.select('.x-grid3-header').setStyle('display', 'none');
},
rowclick : function(grid,rowIndex,e) {
alert(rowIndex);
}
},
});
gridX.render(row);
//Ext.getCmp('grid_lineage').getStore().load({params:{start:0, limit:10}});
storenested.load({params:{start:0, limit:10}});
Please Help
I had the same issue. You will need to get a handle on the nested grid, and call this:
gridX.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick', 'onRowFocus']);

search field in a dataview in extjs

Am trying to put a search field with respect to a data view. There is a toolbar on top of the data view, which consists of a text field. On entering some text in the field, i want to call a search functionality. As of now, i have got hold of the listener to the text field, but the listener is called immediately after the user starts typing something in the text field.
But, what am trying to do is to start the search functionality only when the user has entered at least 3 characters in the text field.How could i do this?
Code below
View
var DownloadsPanel = {
xtype : 'panel',
border : false,
title : LANG.BTDOWNLOADS,
items : [{
xtype : 'toolbar',
border : true,
baseCls : 'subMenu',
cls : 'effect1',
dock : 'top',
height : 25,
items : [{
xtype : 'textfield',
name : 'SearchDownload',
itemId : 'SearchDownload',
enableKeyEvents : true,
fieldLabel : LANG.DOWNLOADSF3,
allowBlank : true,
minLength : 3
}],
{
xtype : 'dataview',
border : false,
cls : 'catalogue',
autoScroll : true,
emptyText : 'No links to display',
selModel : {
deselectOnContainerClick : false
},
store : DownloadsStore,
overItemCls : 'courseView-over',
itemSelector : 'div.x-item',
tpl : DownloadsTpl,
id : 'cataloguedownloads'
}]
Controller:
init : function() {
this.control({
// reference to the text field in the view
'#SearchDownload' :{
change: this.SearchDownloads
}
});
SearchDownloads : function(){
console.log('Search functionality')
}
UPDATE 1: i was able to get hold of the listener after three characters have been entered using the below code:
Controller
'#SearchDownload' :{
keyup : this.handleonChange,
},
handleonChange : function(textfield, e, eOpts){
if(textfield.getValue().length > 3){
console.log('Three');
}
}
any guidance or examples on how to perform the search in the store of the data view would be appreciated.
A proper way would be to subscribe yourself to the change event of the field and check if the new value has at least 3 chars before proceeding.
'#SearchDownload' :{ change: this.handleonChange }
// othoer code
handleonChange : function(textfield, newValue, oldValue, eOpts ){
if(newValue.length >= 3){
console.log('Three');
}
}
Btw. I recommend you to use lowercase and '-' separated names for id's. In your case
itemId : 'search-download'
Edit apply the filter
To apply the filter I would use filter I guess you now the field you want to filter on? Lets pretend store is a variable within your controller than you may replace the console.log() with
this.store.filter('YourFieldName', newValue);
Second param can also be a regex using the value like in the example
this.store.filter('YourFieldName', new RegExp("/\"+newValue+"$/") );
For sure you can also use a Function
this.store.filter({filterFn: function(rec) { return rec.get("YourFieldName") > 10; }});
Thanks you so much sra for your answers. Here is what i did, based on your comments
filterDownloads : function(val, filterWh){
if(filterWh == 1){
var store = Ext.getStore('CatalogueDownloads');
store.clearFilter();
store.filterBy(function (r){
var retval = false;
var rv = r.get('title');
var re = new RegExp((val), 'gi');
retval = re.test(rv);
if(!retval){
var rv = r.get('shortD');
var re = new RegExp((val), 'gi');
retval = re.test(rv);
}
if(retval){
return true;
}
return retval;
})
}
}
i think there is an example of exactly what you are trying to achive .. http://docs.sencha.com/ext-js/4-0/#!/example/form/forum-search.html

Linked Combobox (filter store)

you need when choosing to download a combobox CountryComboBox combobox CityComboBox list of products filtered by field *city_id*. My code works, but not the first time))
Opt for the first combobox value - I go in the second - the filter does not apply. Click again on the first, again in the second - and that's only if it is applied. What am I doing wrong? And then make a filter for the output grid, as well as for the combobox?
ExtJs 3.
My Code:
tbar: [
{
xtype : 'CountryComboBox', // expansion Ext.form.ComboBox
listeners : {
'select' : {
fn : function(combo, value) {
var combobox_city = Ext.getCmp('ProductsProductTypeComboBoxForProduct');
combobox_city.enable();
combobox_city.clearValue();
combobox_city.store.filter('city_id', combo.getValue(), true);
}
}
}
},
{
xtype : 'CityComboBox', // expansion Ext.form.ComboBox
disabled : true,
listeners : {
'select' : {
fn : function(combo, value) {
this.store.filter('people_id', combo.getValue(), true);
}
}
}
},
...

How to autosize form fields

I use form.fields from EXTJS API. My application is totally dynamically.
It is possible to autosize combobox thanks to value which are on store ?
Or i need to make my own method... ?!
Actually, my combobox , is declared as following :
itemId : 'materialid',
xtype : 'combobox',
anchor : '35%',
store : materialstore,
id : 'Material',
queryMode: 'local',
displayField: 'data',
width : 50,
valueField: 'data',
editable : false,
grow : true,
enforceMaxLength : true,
listeners : {
render : function(me){
var obj = materialstore.findRecord('data',materialdefaultvalue);
me.setValue(obj.get('data'),obj);
}
},
padding : '0 30 0 30',
fieldLabel : 'Material',
name : 'material',
listeners : {
blur : function(me){
var fieldvalue = me.getValue();
var sel = monPretree.getView().getSelectedRecords();
for ( var i = 0 ; i < sel.length ; i++){
alert(sel[i].get('id') + ' && ' + material);
}
}
}
Thanks :)
Unfortunately not. Your best bet would be either to set a fixed width (like you have) or set it to '100%'.
A quick note for future questions: it is better to ask them over on the Sencha forums, as you will get a quicker response.

Resources