Displaying Custom Images in 'tools' config options of ext.grid.panel - extjs4

I am only a month old with extjs and still experimenting. My question is: I have a grid panel and within it the 'tools' config options. I am using this to enable/disable a Ext.grid.feature.Grouping variable. The 2 handler functions have the logic to disable/enable the 2 views by clicking on the 2 'cross' buttons that appear on the right side of the header. The logic is fine. However, I would like to display my set of custom images in place of the 'cross' buttons. Can this be done? If yes, how? Do I need to make some changes in the css code for that?
I have looked into the documentation and also done a good search but nothing seems to answer my question.

Specify a custom type config on your tools:
Ext.create('Ext.grid.Panel', {
...
tools: [
{
type: 'enable-grouping',
handler: function() {
...
}
},
{
type: 'disable-grouping',
handler: function() {
...
}
}
]
});
Then define the following classes in a stylesheet to style your new tools:
.x-tool-enable-grouping {
background-image: url('path/to/tool/image/enable-grouping.png');
}
.x-tool-disable-grouping {
background-image: url('path/to/tool/image/disable-grouping.png');
}
The size of a tool image should be 15 x 15 px

Related

Can't get full screen buttons to work with highcharts-vue

I'm using the highcharts-vue wrapper within my vue project. Things are going smooth except for the fact that I can't get the viewFullscreen option to work.
I've set things up following the docs and included the following within my main.js
import exportingInit from 'highcharts/modules/exporting'`
exportingInit(Highcharts);
The export function is working within my charts. For every chart I've set up the options as follow:
exporting: {
buttons: {
contextButton: {
menuItems: ['viewFullScreen', 'downloadPNG', 'downloadJPEG', 'downloadPDF']
}
}
}
alle the buttons ar visible and working except for the viewFullscreen button. that one isn't showing.
Following the docs from the highcharts api there isn't anything mentioned about having to include extra options or so to make use of the vieFullscreen mode.
Any thoughts on this?
You need to change the first string from viewFullScreen to viewFullscreen:
exporting: {
buttons: {
contextButton: {
menuItems: ['viewFullscreen', 'downloadPNG', 'downloadJPEG', 'downloadPDF']
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/ekr2mw7f/
API Reference: https://api.highcharts.com/highcharts/exporting.buttons.contextButton.menuItems

Extjs4 listener for window

In my application i have many windows and panels and im using custom scrollbars. So for each window or panel i need to specify afterlayout listener to get the custom scroll bar
listeners:{
afterlayout: function(c){
fleXenv.fleXcrollMain(c.body.id);
}
}
So what im looking for is i need to add this listener globally for windows and panels so that by adding this code one time should effect on all windows or panels.
Is there any way to do this
It seems that your custom scrollbar is used in all Windows and Panels of your application. Hence there is nothing wrong with extending the core ExtJs classes IMHO.
Implement it as a 'feature' that is enabled by default but - for the rare cases where you don't want the scrollbar - can be disabled.
Ext.define('patch.Ext.panel.Panel-scrollbar', {
override: 'Ext.panel.Panel',
enableCustomScrollbar: true,
afterLayout: function() {
this.fixScrollbar();
this.callParent(arguments);
},
fixScrollbar: function() {
if(this.enableCustomScrollbar) {
// your code
}
}
});
Load with Ext.require('patch.Ext.panel.Panel-scrollbar') or add it as dependency (requires) to your application definition.
Ext.window.Window extends from Ext.panel.Panel, hence it will inherit the behavior.
You can make your own panel and window extending ExtJS default components. You can define desired listener, set up xtypes and then use these modified components in your application.
Another solution would be to override existing Ext.panel.Panel and Ext.window.Window with Ext.override
IMHO, I think the best way to do this is to define your personal Window/Panel class. Yes, one way is to use Ext.override function but I don't think it's a good idea.
I suggest you to do this:
Ext.define ('MyCustomWindow', {
extend: 'Ext.window.Window' ,
listeners: {
afterlayout: function (win) {
fleXenv.fleXcrollMain (win.body.id);
}
}
}
Ext.define ('MyCustomPanel', {
extend: 'Ext.panel.Panel' ,
listeners: {
afterlayout: function (panel) {
fleXenv.fleXcrollMain (panel.body.id);
}
}
}
Now, you can instantiate MyCustomWindow and MyCustomPanel, leaving Ext.window.Window and Ext.panel.Panel unchanged.
Another way is to use WindowManager and PanelManager (this one defined by yourself):
Ext.WindowManager.register (window1);
Ext.WindowManager.register (window2);
Ext.WindowManager.register (window3);
Ext.WindowManager.each (function (win) {
win.on ('afterlayout', function (window) {
fleXenv.fleXcrollMain (window.body.id);
});
});
In this case, first you have to instantiate your windows and panels, register them to their managers and then invoke the each function as I did in the example above.

Dynamically adding html to panel

I am designing an app in sencha touch2. I have a panel object in my JS file. I need to dynamically set the text/html for this component. The store for this component is defined at the application level. Following is the thing I worked out:
Ext.define('class_name',{
....
config : {
pnlObj : null,
...
}
initialize : function() {
this.config.pnlObj = Ext.create('Ext.Panel');
var store = Ext.data.Storemanager.lookup('some_store');
store.on('load',this.loadStore,this);
this.setItems([{
//some items here
{
flex : 2,
// id : 'somepnl',
config : this.config.pnlObj
}
}]);
},
loadStore : function(store, rec) {
var text = rec.get('text');
var panel = this.config.pnlObj;
// var panel = Ext.getCmp('somepanl');
panel.setHtml(text);
}
});
When I inspect the inspect the element using Firebug console, I can find the panel added there. But I am not able to set the html dynamically. no html text is set there. I tried adding it using panel.add() & panel.setItems() method which doesn't work. If I give an id to that panel(somepanel here) and try to access it using Ext.getCmp('smpanel') then in that case it works fine. I have found that using Ext.getCmp() is not a good practice and want to avoid it as it might somewhere break my code in the future.
I guess the way I am instantiating the panel object is creating some issue. Can someone suggest the best way of doing it?
The recommended way to manipulate your components in Sencha Touch 2 is using controller, through refs and control configs. For example, your panel has a config like this: xtype:'myPanel', then in your controller:
refs: {
myPanel: 'myPanel'
}
control:{
myPanel: {
on_an_event: 'set_html_for_my_panel'
}
}
Lastly, define your function:
set_html_for_my_panel: function()
{
this.getMyPanel().setHtml('my_updated_html');
}
P/S: Behind the scene, Sencha Touch 2 uses Ext.ComponentQuery for refs in controllers

Set a default UI across all components in Sencha Touch

Within Sencha Touch, is it possible to define a default UI , like "light" or "dark", that applies to all components (unless overwritten explicitly)?
The aim is to avoid having to declare ui: "dark", or any custom UI that is made, for every element.
Cheers!
You can try this:
Ext.apply(Ext.Component.prototype, {
getUi: function() {
var defaultUi = 'light';
// value of [this.config.ui] is ignored here
// we can use something like forcedUi
return (this.forcedUi) ? this.forcedUi : defaultUi;
}
})
The disadvantage of this code is that we need to specify another variable for applying ui different from 'light' (because variable 'ui' via getUi() will always return 'light'):
...
items: [{
xtype: 'button',
forcedUi: 'dark'
}]
...
I am stuck on Touch 1.1 so sunsay's solution didn't work for me, but this did:
Ext.CustomToolbar = Ext.extend(Ext.Toolbar,
{
ui:'app'
});
Ext.reg('toolbar', Ext.CustomToolbar);
So, it's still component-by-component-type, but not component-by-component-instance. And since you can overwrite the "reg", no need for custom x-types all over the place, either.
I assume that you know about sencha touch styles and themes. Otherwise you can download a pdf file from this link which clearly describes about how to do it...
http://f.cl.ly/items/d9df79f57b67e6e876c6/SenchaTouchThemes.pdf
In it they are mentioning about scss file where you can specify the base-color, ie
$base-color: #4bb8f0 ;
$base-gradient: 'glossy';
Then run it ... you can see the toolbars and buttons created with the color and gradient you have mentioned.

How to add Tools dynamically in an Ext Js window?

I wanto to add a tool (search, help, gear, ...) in a window dynamically, like this:
http://www.rahulsingla.com/sites/default/files/content/blog/extjs/extjs-panel-add-tool.htm
And I need to create more than one instance of UIMyWindow at the same time.
However, I'm using Ext Designer which generates 2 files:
MyWindow.ui.js: class declaration.
MyWindow.js: methods implementation.
Besides Ext Designer hasn't an option Tools at design time (I didn't find).
I was adding the tool outside MyWindow.js and MyWindow.ui.js, like this:
var winMyWindow = new UIMyWindow({
autoShow: 'true',
tools: [{
type:'gear',
handler: function(){
// Some code...
}
}]
});
But I want to put this block inside MyWindow.js. So, I did this:
UIMyWindow = Ext.extend(UIMyWindowUi, {
tools: [{
type:'gear',
handler: function(){
// Some code...
}
}],
initComponent: function() {
UImenuDock.superclass.initComponent.call(this);
If you ask me "Why not to put this code inside MyWindow.ui.js?", I would answer "because I don't want to put this code manually every time I make changes in the design file (Ext Designer)".
Well, if I open one window, it's seems work ok, but if I open a second at the same time, the tools are duplicated in the second window...
So, any idea how to add tools dynamically in MyWindow.js in this specific case?
put 'tools' into initComponent
UIMyWindow = Ext.extend(UIMyWindowUi, {
initComponent: function() {
this.tools = [{
type:'gear',
handler: function(){
// Some code...
}
}],
UImenuDock.superclass.initComponent.call(this);