Clearing ExtJS combobox input field - input

I have an Ext.form.ComboBox with the following properties:
fieldLabel: 'Regiune',
valueField: 'id',
displayField: 'reg',
id: 'cbRegR',
typeAhead: true,
store: new Ext.data.JsonStore({...}),
mode: 'local',
emptyText: '',
listeners:{...}
The problem is that I have to manually delete the combobox' input field after selecting a value from the dropdown list to view all the list items. The matter is the list displays only the items that begin with letters in input field.
How can I clear the input field on expanding dropdown list? I tried the following but it doesn't work:
listeners: { 'expand': function() { cbRegR.clearValue(); } }
Seems to be easy but it ain't so for me.. Any bright ideas? Thanks in advance.

Adding the config property to your combobox
triggerAction: 'all'
might do the trick, without the need to register an expand event handler or clearing the combobox's value

It is an intrinsic behaviour of Ext JS ComboBox-es to filter the list items based on the field value, as you already know.
You could perceivably override the expand() method, making additions to clear out the value before it renders the list. EG:
Ext.override(Ext.form.ComboBox, {
expand : function(){
if(this.isExpanded() || !this.hasFocus){
return;
}
//ADDITIONS HERE:
this.clearValue();
this.doQuery("", true);
//ADDITIONS END HERE
if(this.title || this.pageSize){
this.assetHeight = 0;
if(this.title){
this.assetHeight += this.header.getHeight();
}
if(this.pageSize){
this.assetHeight += this.footer.getHeight();
}
}
if(this.bufferSize){
this.doResize(this.bufferSize);
delete this.bufferSize;
}
this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
// zindex can change, re-check it and set it if necessary
this.list.setZIndex(this.getZIndex());
this.list.show();
if(Ext.isGecko2){
this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
}
this.mon(Ext.getDoc(), {
scope: this,
mousewheel: this.collapseIf,
mousedown: this.collapseIf
});
this.fireEvent('expand', this);
}
});

The expand event is the good one but you have to be careful about the scope.
listeners: {
'expand': function() {
cbRegR.clearValue();
},
scope:this
}
Does setting the scope helps?

Using cbRegR won't work, because it's an undefined variable. Either use
listeners: { 'expand': function() { Ext.getCmp('cbRegR').clearValue(); } }
or, a more sophisticated approach:
listeners: { 'expand': function(self) { self.clearValue(); } }

Related

Why it is hard to use vue-i18n in vue data() (why it is not reactive)

I am using vue-i18n in a vue project. And I found it really confusing when using some data in vue data with i18n. Then if I change locale, that data is not reactive. I tried to return that data from another computed data but anyways it is not reactive because i18n is written in data. *My situation - * I want to show table with dropdown(list of columns with checkbox) above it. When user checks a column it will be showed in table if unchecks it won't. It is working fine until I change locale. After changing locale table columns is not translated but dropdown items is reactively translated and my code won't work anymore. Here is some code to explain better: In my myTable.vue component I use bootstrap-vue table -
template in myTable.vue
<vs-dropdown vs-custom-content vs-trigger-click>
<b-link href.prevent class="card-header-action btn-setting" style="font-size: 1.4em">
<i class="fa fa-th"></i>
</b-link>
<vs-dropdown-menu class="columns-dropdown">
<visible-columns :default-fields="columns" #result="columnListener"></visible-columns>
</vs-dropdown-menu>
</vs-dropdown>
<b-table class="generalTableClass table-responsive" :fields="computedFieldsForTable">custom content goes here</b-table>
script in myTable.vue
data(){
return {
fieldsForTable: [];
}
},
computed: {
computedFieldsForTable () {
return this.fieldsForTable;
},
columns() {
return [
{
key: 'id',
label: this.$t('id'),,
visible: true,
changeable: true
},
{
key: 'fullName',
label: this.$t('full-name'),,
visible: true,
changeable: true
},
{
key: 'email',
label: this.$t('email'),,
visible: true,
changeable: true
}
]
}
},
mounted () {
this.fieldsForTable = this.filterColumns(this.columns);
},
methods: {
filterColumns(columns = []) {
return columns.filter(column => {
if (column.visible) {
return column
}
})
},
columnListener ($event) {
this.fieldsForTable = this.filterColumns($event)
}
}
Can someone give me some advice for this situation ?
*EDIT AFTER SOME DEBUGGING: I think when filtering columns(in computed) and returning it for fieldsForTable inside filterColumns(columns) method, it actually returning array(of objects) with label='Label Name' not label=this.$t('labelName'). So after filtering the new array has nothing to do with vue-i18n. My last chance is reloading the page when locale changes.
Trying modify computedFieldsForTable as follows. You need to reference this.columns in computedFieldsForTable, so that Vue can detect the change of labels in this.columns.
computedFieldsForTable () {
return this.filterColumns(this.columns);
},
EDITED: put your this.columns in data. Then
columnListener ($event) {
this.columns = $event;
}
I hope i didn't misunderstand what you mean.
EDITED (again):
Maybe this is the last chance that I think it can work. Put columns in computed() still and remove computedFieldsForTable. Finally, just leave fieldsForTable and bind it on fields of <b-table>.
watch: {
columns(val) {
this.fieldsForTable = this.filterColumns(val)
}
},
method: {
columnListener ($event) {
this.fieldsForTable = this.filterColumns($event)
}
}
However, I think it is better and easier to reload page whenever local change. Especially when your columns have a more complex data structure.

How can I get list selected items in sencha touch 2.3.1

How can I get selected items of Ext.List on sench-touch 2.3.1?
Thank you.
[View]
{
xtype: 'list',
itemTpl: '{MATERIAL_ID} {TEXT}',
mode: 'MULTI'
}
[Controller]
'queryresult #queryButton': {
tap: function(){
var list = Ext.ComponentQuery.query('queryresult #list')[0];
//todo: get selected items
}
}
Strangely, I use list.getSelection(), return
"TypeError: 'undefined' is not a function (evaluating 'list.getSelectiion()')"
use list.selected.getRange() can get right result.....
But...document say
function getSelection(){ return list.selected.getRange(); }
var records = list.getSelection();
Check out this documentation page:
http://docs.sencha.com/touch/2.3.1/#!/api/Ext.dataview.List-method-getSelection

CheckboxModel makes some particular fields editable

i am using checkboxmodel plugin for a checkbox column.But, what i want is that 'if i check a column some cells of that row will be editable'...i searched a lot but no luck.I am working with MVC pattern and because of the plugin i dont know how to handle it
/**Grid View**/
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
selType: 'cellmodel',
selModel: Ext.create('Ext.selection.CheckboxModel', {
checkOnly: true,
listeners: {
selectionchange: function(model, records) {
if (records[0]) {
//make any cell of a field editable
}
}
}
}),
{
header:'name',
dataIndex:'name'},
{
header:'Quantity',
dataIndex:'quantity',
}
here if i check any row i want to make the grid's quantity field editable...This would be nice if someone can help...
Try this:
1) create editor plugin instance for reference:
var editor = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
});
2) use this instance in grid plugin definition:
plugins: [
editor
]
3) modify your selModel definition to look something like this:
selModel: Ext.create('Ext.selection.CheckboxModel', {
checkOnly: true,
listeners: {
selectionchange: function(model, records) {
if (records[0] && !editor.editing) {
editor.startEdit(records[0], 2); // 2 is the number of column you want to edit
}
}
}
}),
Using this solution you will be able to edit only one cell when grid row is checked. Also you will need to implement additional logic to stop editing previously edited cell in case if selection change etc... Hope this hint will help you.

Nested grid in ExtJS 4.1 using Row Expander

On the front-end I have a Calls grid. Each Call may have one or more Notes associated with it, so I want to add the ability to drill down into each Calls grid row and display related Notes.
On the back-end I am using Ruby on Rails, and the Calls controller returns a Calls json recordset, with nested Notes in each row. This is done using to_json(:include => blah), in case you're wondering.
So the question is: how do I add a sub-grid (or just a div) that gets displayed when a user double-clicks or expands a row in the parent grid? How do I bind nested Notes data to it?
I found some answers out there that got me part of the way where I needed to go. Thanks to those who helped me take it from there.
I'll jump straight into posting code, without much explanation. Just keep in mind that my json recordset has nested Notes records. On the client it means that each Calls record has a nested notesStore, which contains the related Notes. Also, I'm only displaying one Notes column - content - for simplicity.
Ext.define('MyApp.view.calls.Grid', {
alias: 'widget.callsgrid',
extend: 'Ext.grid.Panel',
...
initComponent: function(){
var me = this;
...
var config = {
...
listeners: {
afterrender: function (grid) {
me.getView().on('expandbody',
function (rowNode, record, expandbody) {
var targetId = 'CallsGridRow-' + record.get('id');
if (Ext.getCmp(targetId + "_grid") == null) {
var notesGrid = Ext.create('Ext.grid.Panel', {
forceFit: true,
renderTo: targetId,
id: targetId + "_grid",
store: record.notesStore,
columns: [
{ text: 'Note', dataIndex: 'content', flex: 0 }
]
});
rowNode.grid = notesGrid;
notesGrid.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick', 'onRowFocus']);
notesGrid.fireEvent("bind", notesGrid, { id: record.get('id') });
}
});
}
},
...
};
Ext.apply(me, Ext.apply(me.initialConfig, config));
me.callParent(arguments);
},
plugins: [{
ptype: 'rowexpander',
pluginId: 'abc',
rowBodyTpl: [
'<div id="CallsGridRow-{id}" ></div>'
]
}]
});

Extjs4.1 -- How to create a subclass for render / send a parameter?

I have a checkitem menu and I want to add icons to each menu item, so I inserted each icon after the menu item is rendered.
peace of my code:
{ xtype: 'menucheckitem',
text: 'First Arrow'
listeners: {
render: {
fn: me.onMenucheckitemRender,
scope: me
}
}
}
onMenucheckitemRender: function (abstractcomponent, options)
{
Ext.DomHelper.insertAfter(abstractcomponent.getEl().down(".x-menu-item-icon"), {
tag: 'img',
src: "icons/arrow1.png"
});
}
This works just fine, but since I will need it many times with different icons, I would like to know how to create a subclass so I can reuse this functionality.
Thank you
use the Ext.define method and the extend property.
Ext.define('SomeNamespace.menu.menucheckitemWithIcon', {
extand: 'Ext.menu.CheckItem',
alias: 'widget.menucheckitemWithIcon',
.
.
.
});