Sorry, I forgot that I have a blog.
Classic ASP was the last scripting language that I used from the universe of Microsoft. PHP is enough to make me happy and my clients. (Hey!, which client cares about the language of your choice?
)
Anyway, I won’t make a comparison of languages. I am not that stupid. I just want to tell you something about how I am impressed with Ext.Direct and the server-side stack for ASP.NET MVC.
DWR is popular enough in Java world. They know a lot the concept of “remoting server-side methods to the client-side”. Ext.Direct has implementations for several other languages and frameworks. Sadly, CakePHP is not in the list of supported frameworks but ASP.NET MVC has one of the powerful one.
You define couple of config values in web.config and that’s all! Just extend your controller from DirectController and use DirectResult typed methods to return your result to the browser. You can use several attributes for classes and methods to hide them in Ext.Direct remoting api object returned to the browser.
By the way, I was curious about ASP.NET. I learned MVC pattern from CakePHP. C# and PHP have similar syntax. Those smooth out my learning curve in ASP.NET MVC. We can discuss pros and cons of ASP.NET etc. but one thing is clear, Visual Studio. I am using Zend Studio and have tried several others but I have never met that quality of IDE before.
Finally, you are right. It is hard to follow. I was talking about ASP, PHP, then Ext.Direct and ASP.NET MVC came to the picture. Let’s say that this post is a sign of life.
I have a lot to share with you, jQuery, Mootools, Zend Framework, Posh, gadget development, new released ExtJS 3.0, Moodle, PHP 5.3 release, and much more…
New version of Ext JS, 2.2.1, is announced and we are so happy, aren’t we?
Another Ext JS news: Ext Conference 2009. I wish, I could attend. I hope, I am going to be there in the next conference…
In this short tutorial, I am going to show you to simply the icon management in Ext JS. It is not a complete solution. If you want to see a more professional one, see Ext.ux.TDGi.iconMgr from TDG innovations.
When you want to use icons in your Ext JS application you either have to use “icon” config option by giving path to your icon or “iconCls” by defining a new CSS class. The latter one is more prefferable way of doing it but it means that you need to define a CSS class for each of your icons. Let’s create a new function to make it easy!
Ext.ux.Icon = function(icon){
var path = 'img/icons/';
if(!Ext.util.CSS.getRule('.icon-'+icon)){
Ext.util.CSS.createStyleSheet('.icon-'+icon+' { background-image: url('path+icon+'.png) !important; }');
}
return 'icon-'+icon;
}
Change the value of “path” where your PNG icons are located. Don’t tell me you don’t hear the famous icon collection from famfamfam!
And call it like:
...,
iconCls: Ext.ux.Icon('excel'),
...,
It is going to add a new CSS rule “icon-excel” with background-image “excel.png” and add it to the head of your page.
I can hear you say why you have to use PNG extension? You are right, you don’t have. Just modify Ext.ux.Icon by adding a second argument ,maybe, called as extension and pass the icon’s extension:
Ext.ux.Icon = function(icon, extension){
var path = 'img/icons/';
if(!Ext.util.CSS.getRule('.icon-'+icon)){
Ext.util.CSS.createStyleSheet('.icon-'+icon+' { background-image: url('path+icon+'.'+extension+') !important; }');
}
return 'icon-'+icon;
}
...,
iconCls: Ext.ux.Icon('excel', 'png'),
...,
or by removing the extension part and passing the name of icon with its extension:
Ext.ux.Icon = function(icon){
var path = 'img/icons/';
if(!Ext.util.CSS.getRule('.icon-'+icon)){
Ext.util.CSS.createStyleSheet('.icon-'+icon+' { background-image: url('path+icon+') !important; }');
}
return 'icon-'+icon;
}
...,
iconCls: Ext.ux.Icon('excel.png'),
...,
Don’t use Ext.ux.Icon if you are going to use hundreds of CSS rules because each class is defined in its own “style” tag and it can affect browser rendering performance.
It’s not important what you think, it’s important what you do…
I am using Ext JS in my web application projects and I decided that it is time to give back to the community.
If you are developing a CRUD application and using grids to display data from your database you should define similar column models, fields, readers, stores etc. for your grids. It is not a big concern if it is not the first time you do the same things or you have your own components not to repeat yourself. But what if your database table needs a change in its structure? Let me guess… You change field and column model definitions in your grids and doing the same again and again even there are small changes.
Here is a small Ext JS component that I wrote:
Ext.ux.DynamicGridPanel = Ext.extend(Ext.grid.GridPanel, {
initComponent: function(){
/**
* Default configuration options.
*
* You are free to change the values or add/remove options.
* The important point is to define a data store with JsonReader
* without configuration and columns with empty array. We are going
* to setup our reader with the metaData information returned by the server.
* See http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader for more
* information how to configure your JsonReader with metaData.
*
* A data store with remoteSort = true displays strange behaviours such as
* not to display arrows when you sort the data and inconsistent ASC, DESC option.
* Any suggestions are welcome
*/
var config = {
viewConfig: {forceFit: true},
enableColLock: false,
loadMask: true,
border: false,
stripeRows: true,
ds: new Ext.data.Store({
url: this.storeUrl,
reader: new Ext.data.JsonReader()
}),
columns: []
};
Ext.apply(this, config);
Ext.apply(this.initialConfig, config);
Ext.ux.DynamicGridPanel.superclass.initComponent.apply(this, arguments);
},
onRender: function(ct, position){
this.colModel.defaultSortable = true;
Ext.ux.DynamicGridPanel.superclass.onRender.call(this, ct, position);
/**
* Grid is not masked for the first data load.
* We are masking it while store is loading data
*/
this.el.mask('Loading...');
this.store.on('load', function(){
/**
* Thats the magic!
*
* JSON data returned from server has the column definitions
*/
if(typeof(this.store.reader.jsonData.columns) === 'object') {
var columns = [];
/**
* Adding RowNumberer or setting selection model as CheckboxSelectionModel
* We need to add them before other columns to display first
*/
if(this.rowNumberer) { columns.push(new Ext.grid.RowNumberer()); }
if(this.checkboxSelModel) { columns.push(new Ext.grid.CheckboxSelectionModel()); }
Ext.each(this.store.reader.jsonData.columns, function(column){
columns.push(column);
});
/**
* Setting column model configuration
*/
this.getColumnModel().setConfig(columns);
}
/**
* Unmasking grid
*/
this.el.unmask();
}, this);
/**
* And finally load the data from server!
*/
this.store.load();
}
});
How to use it?
new Ext.ux.DynamicGridPanel({
id: 'my-grid',
storeUrl: 'server/url/address/',
rowNumberer: true,
checkboxSelModel: true,
sm: new Ext.grid.CheckboxSelectionModel(),
});
And here is the JSON which should be returned from server to dynamically create column and field definitions:
{
"metaData": {
"totalProperty": "total",
"root": "records",
"id": "id",
"fields": [
{
"name": "id",
"type": "int"
},
{
"name": "name",
"type": "string"
}
]
},
"success": true,
"total": 50,
"records": [
{
"id": "1",
"name": "AAA"
},
{
"id": "2",
"name": "BBB"
}
],
"columns": [
{
"header": "#",
"dataIndex": "id"
},
{
"header": "User",
"dataIndex": "name"
}
]
}
The code itself is somewhat self-explanatory but for newbie users learning center is a good start to understand how to extend Ext JS or simply understand how the framework works.
Suggestions and comments are welcome…