Clear the Search Text field in LiveSearchGridPanel - extjs

We are using the LiveSearchGrid Panel in ExtJS 4.2.1 similar to the example below, with Pagination. When the user searches for a record in one page, and then goes to another page, the search text field is NOT cleared, and clicking on the next or previous buttons show some random results (which are based the previous search). How can I clear this Search Text Field in the LiveSearchGridPanel?
http://dev.sencha.com/deploy/ext-4.0.1/examples/grid/live-search-grid.html
I looked into the API documentation of LiveSearchGridPanel, but it does not provide an easy handle to the Search Text Field.

Add a listener on the beforechange event of the paging toolbar. Something like this:
{
xtype: 'pagingtoolbar',
// ...
listeners: {
beforechange: function() {
this.up('grid').down('textfield[name=searchField]').setValue('');
}
}
}

Related

Show PopupMenu in Ag-Grid

How can I show programmatically the column PopupMenu in Ag-Grid?
PopupMenu Ag-Grid
With the gridApi you can hide it, but not show it
gridApi.hidePopupMenu()
I try also with the FilterInstance and the columnApi, but I haven't found anything that works
gridApi.getFilterInstance(colKey)
gridColumnApi?.getColumn(colKey) ...
Thanks
you can add a little workaround to open the filter popup:
// find the header menu button for the desired column
const colElement = document.querySelector("div[col-id='" + desiredColumn.getColId() + "'] > .ag-cell-label-container > .ag-header-cell-menu-button");
colElement.dispatchEvent(new Event("click")); // simulate a click on the menu button
// the next part ist to switch to the filter tab:
setTimeout(() => { // give the browser some time to render the menu
const tabElement = document.querySelectorAll("div.ag-tabs-header > .ag-tab")[1]; // select the filter tab
if (!tabElement.classList.contains("ag-tab-selected")) { // if the filter tab is not selected already
tabElement.dispatchEvent(new Event("click")); // click the filter tab
}
}, 10);
Basically, you locate the button in the DOM and execute a virtual click on it. It's not pretty but it works well, maybe we'll get an API for this in the future.
What you're wanting to do is to access getFilterInstance() of the Ag Grid API. Here's the relevant documentation: https://www.ag-grid.com/javascript-grid/filter-api/
Here's one way of accessing, and setting the filter using the getFilterInstance method
var FilterComponent = gridOptions.api.getFilterInstance('Status');
FilterComponent.selectNothing(); //Cleared all options
FilterComponent.selectValue('Approved') //added the option i wanted
FilterComponent.onFilterChanged();
Here's a related Stackoverflow question: how to pre-set column filter in ag-grid

Extjs combo setbind not working

I'm using the following code in order to set the selected value:
this.myCombo.setBind('{rec.my_value}');
All my data is in "rec".
Options for choose are being filled in the combo as expected but no value is set to the selected value.
Why is this happening and how to solve?
Tried already put the above bind after data is being loaded and after page is already rendered, but without success.
You can use code something like this:
{
xtype:'combo',
store:'mystore',
valueField:'id', // you will get this value by default after selection
displayField:'name', // it will responsible to show display as option on combo
listeners: {
change : function(cmp){
var value = cmp.getValue();
}
}
}
Where id and name are the record data of store. Now, whenever you select any option, then it will display.

Sencha Touch 1.1: Setting Panel properties after selecting item in List

I'm using Sencha Touch 1.1. I have a Ext.List and when the user selects an item, I switch to the details page using
rootPanel.setActiveItem('details');
That works fine. Now I want to get the details of the selected item and populate properties in the 'details' panel. How do I do that?
At the moment I'm passing the record around to the various panels of the details page by using this code:
onItemDisclosure: function (record) {
// user has selected a Country from the Country List.
// TODO: There must be a better way to pass the data around
CountryDetailsToolbar.setTitle(record.data.title);
var upperData = { upper: record.data.title.toUpperCase()};
CountryDetailsHeaderLeft.update(upperData);
CountryDetailsHeaderMonth.update(record.data);
viewport.setActiveItem('CountryDetailsCarousel');
}
This seems a bit messy to me. Is there a cleaner way to set titles and update panels with the data "record"?
you can use rootPanel.getActiveItem() to get instance of currently selected panel, i am not sure about what do you mean by populate properties in the details tab
Update:
i think there isn't any problem in passing record data between panels, i think that is the most efficient way
onItemDisclosure: function (record) {
// user has selected a Country from the Country List.
var title = record.get('title');
CountryDetailsToolbar.setTitle(title);
CountryDetailsHeaderLeft.update({ upper: title.toUpperCase() });
CountryDetailsHeaderMonth.update(record.data);
viewport.setActiveItem('CountryDetailsCarousel');
}

ExtJS 4 ComboBox AutoComplete

I have an extjs combobox used for auto-complete having following configuration:
xtype:'combo',
displayField: 'name',
valueField:'id',
store: storeVar,
queryMode: 'remote',
minChars:2,
hideTrigger:true,
forceSelection:true,
typeAhead:true
There are two issues being faced by me:
a. If a user chooses a value from the list returned from server, but later wants to remove that value and keep combo-box empty, then also the old values re-appears on blur, not allowing combo-box to remain empty. How can I allow empty value in this combo-box in such a case? I understand it could be due to forceSelection:true, but then I need to keep it true as otherwise user can type any random value.
b. When the server returns an empty list, I want to display a message - No Values Found. I tried doing this, by putting this value in the displayField entity, i.e., {id:'', name:'No Value Found'}. But then in this case, the user is able to choose this value and send it to server which is not what is expected. Thus, how can I display the message for empty list?
Could someone please throw light on this?
For the issue related to forceSelection in the question above, following is the hack created which can serve the expected purpose:
Ext.override(Ext.form.field.ComboBox,{
assertValue: function() {
var me = this,
value = me.getRawValue(),
rec;
if (me.multiSelect) {
// For multiselect, check that the current displayed value matches the current
// selection, if it does not then revert to the most recent selection.
if (value !== me.getDisplayValue()) {
me.setValue(me.lastSelection);
}
} else {
// For single-select, match the displayed value to a record and select it,
// if it does not match a record then revert to the most recent selection.
rec = me.findRecordByDisplay(value);
if (rec) {
me.select(rec);
} else {
if(!value){
me.setValue('');
}else{
me.setValue(me.lastSelection);
}
}
}
me.collapse();
}
});
This needs to be included after library files of extjs have been included.
For the other issue of message to be shown at No Values Found - emptyText - works fine as suggested by Varun.
Hope this helps somone looking for something similar.
I've done this for Ext JS 3.3.1. I don't know if they apply to Ext JS 4, though I guess they should.
For the first problem, set autoSelect : false. autoSelect is by default set to true. This will work only if allowBlank : true is set. From the docs
true to select the first result gathered by the data store (defaults
to true). A false value would require a manual selection from the
dropdown list to set the components value unless the value of
(typeAheadDelay) were true.
For the second problem, use listEmptyText. From the docs
The empty text to display in the data view if no items are found.
(defaults to '')
Cheers.

how to enable button in extjs?

I am new to ExtJs(using EXT js 4 ), I am trying out simple code.
I have a submit button which is set disabled by default
buttons: [{
text: 'Submit',
id:'submit',
disabled:true
}]
I want to enable the button based on certain conditon.Something like
if (validation_status== "success") {
//Enable the submit button
//Ext.get('submit').dom.disabled = false; -- Not working
//Ext.get('submit').enable(); -- Not working
}
I tried above 2 option. Which did not worked for me.
Can anyone help me out?
Use this:
Ext.getCmp('submit').enable();
When you use Ext.getCmp(), it gives you the component which has a number of component methods to use. If you use Ext.get(), it gives you the element with a number of dom element modification functions. So, its always better to test in firebug console for any of these to know what methods are there.
console.log(Ext.getCmp('submit'));
console.log(Ext.get('submit'));

Resources