Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name'],
associations: [{ type: 'hasOne', model: 'Status', associationKey: 'status'}]
});
Ext.define('Status', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'title', type: 'string', mapping: 'st_title' }
]
});
Ext.onReady(function () {
var store = Ext.create('Ext.data.ArrayStore', {
model: 'User',
data: [
{ id: '1', name: 'user-1', status: { id: 2, st_title: 'disabled'} },
{ id: '2', name: 'user-2', status: { id: 1, st_title: 'active'} },
{ id: '3', name: 'user-3', status: { id: 3, st_title: 'deleted'} },
{ id: '4', name: 'user-4', status: { id: 1, st_title: 'active'} },
{ id: '5', name: 'user-5', status: { id: 3, st_title: 'deleted'} }
],
proxy: {
type: 'memory',
reader: {
type: 'json'
}
}
});
Ext.widget({
xtype: 'grid',
title: 'Users',
width: 400,
height: 180,
store: store,
renderTo: 'output',
columns: [
{ text: 'id', dataIndex: 'id' },
{ text: 'name', dataIndex: 'name' },
{
text: 'status',
renderer: function (v, m, r) {
return r.getStatus().get('title');
}
}
]
});
});
To set treecolumn icon you can use "iconCls" property.
Ext.define('MenuItem', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' },
{ name: 'Disabled', type: 'bool' },
{
name: 'iconCls',
type: 'string',
convert: function (v, r) {
return r.get('Disabled') ? 'icon-disabled' : 'icon-enabled'
}
}
]
});
Ext.define('MenuItemsTree', {
extend: 'Ext.data.TreeStore',
model: 'MenuItem',
root: {
expanded: true,
Name: "My Root",
children: [
{ Name: "Child 1", Disabled: false, leaf: true },
{
Name: "Child 2",
Disabled: true,
expanded: true,
children: [
{ Name: "GrandChild", Disabled: true, leaf: true }
]
}
]
}
});
Ext.onReady(function () {
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree With Custom Icons',
width: 400,
height: 150,
store: Ext.create('MenuItemsTree'),
rootVisible: true,
renderTo: 'output',
columns: [
{ header: 'Name', dataIndex: 'Name', xtype: 'treecolumn', width: 150 },
{ header: 'Disabled', dataIndex: 'Disabled', width: 150 }
]
});
});
.x-tree-icon.icon-enabled {
margin: 7px 4px 0 4px;
background: url("/content/images/li.gif") no-repeat scroll 0 -6px transparent;
height: 6px;
width: 6px;
}
.x-tree-icon.icon-disabled {
margin: 7px 4px 0 4px;
background: url("/content/images/li.gif") no-repeat scroll 0 0 transparent;
height: 6px;
width: 6px;
}
ExtJs 4: How To Add Grid Cell Tooltip
Ext.onReady(function () {
// Init the singleton. Any tag-based quick tips will start working.
Ext.tip.QuickTipManager.init();
Ext.widget('grid', {
title: 'Users',
store: {
fields: ['name', 'email', 'comment'],
data: [
{ 'name': 'Lisa', 'email': 'lisa@simpsons.com', 'comment': 'some comment' },
{ 'name': 'Bart', 'email': 'bart@simpsons.com', 'comment': 'comment' },
{ 'name': 'Homer', 'email': 'home@simpsons.com', 'comment': 'some very long comment' },
{ 'name': 'Marge', 'email': 'marge@simpsons.com', 'comment': 'some very very very very long comment' }
]
},
columns: [
{ header: 'Name', dataIndex: 'name', width: 100 },
{ header: 'Email', dataIndex: 'email', width: 150 },
{
header: 'comment',
dataIndex: 'comment',
flex: 1,
renderer: function (value, meta, record) {
var max = 15;
meta.tdAttr = 'data-qtip="' + value + '"';
return value.length < max ? value : value.substring(0, max - 3) + '...';
}
}
],
width: 400,
renderTo: 'output'
});
});
How To Change Grid Cell Background Color
Ext.onReady(function () {
Ext.widget('grid', {
title: 'Users',
store: {
fields: ['name', 'email', 'online'],
data: [
{ 'name': 'Lisa', "email": "lisa@simpsons.com", "online": true },
{ 'name': 'Bart', "email": "bart@simpsons.com", "online": false },
{ 'name': 'Homer', "email": "home@simpsons.com", "online": true },
{ 'name': 'Marge', "email": "marge@simpsons.com", "online": true }
]
},
columns: [
{
header: 'Name',
dataIndex: 'name',
renderer: function (value, meta, record) {
meta.tdCls = record.get('online') ? 'user-online' : 'user-offline';
return value;
}
},
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Online', dataIndex: 'online' }
],
width: 400,
renderTo: 'output'
});
});
.x-grid-cell.user-online
{
background-color: #9fc;
}
.x-grid-cell.user-offline
{
background-color: #ffc;
}
How to render gridpanel in html element?
Ext.onReady(function () {
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
width: 500,
store: {
fields: ['name', 'email', 'phone'],
data: [
{ 'name': 'Lisa', "email": "lisa@simpsons.com", "phone": "555-111-1224" },
{ 'name': 'Bart', "email": "bart@simpsons.com", "phone": "555-222-1234" },
{ 'name': 'Homer', "email": "home@simpsons.com", "phone": "555-222-1244" }
]
},
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Phone', dataIndex: 'phone' }
],
renderTo: 'container'
});
});
<div id="container"></div>
How To Render Image To Grid Field
Ext.onReady(function () {
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: {
fields: ['name', 'email', 'online'],
data: [
{ 'name': 'Lisa', "email": "lisa@simpsons.com", "online": true },
{ 'name': 'Bart', "email": "bart@simpsons.com", "online": false },
{ 'name': 'Homer', "email": "home@simpsons.com", "online": true },
{ 'name': 'Marge', "email": "marge@simpsons.com", "online": true }
]
},
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{
header: 'Online',
dataIndex: 'online',
align: 'center',
width: 50,
renderer: function (value, meta, record) {
var url = value == true ?
'/Content/images/icons/user-online.png' :
'/Content/images/icons/user-offline.png';
meta.tdCls = 'td-img';
return Ext.String.format('<img src="{0}" />', url);
}
}
],
width: 400,
renderTo: 'output'
});
});
.td-img .x-grid-cell-inner{
padding: 0;
}
How To Change Grid Row Background Color
Ext.onReady(function () {
Ext.widget('grid', {
title: 'Users',
viewConfig: {
stripeRows: false,
trackOver: false,
getRowClass: function (record, rowIndex, rowParams, store) {
return record.get('online') ? 'user-online' : 'user-offline';
}
},
store: {
fields: ['name', 'email', 'online'],
data: [
{ 'name': 'Lisa', "email": "lisa@simpsons.com", "online": true },
{ 'name': 'Bart', "email": "bart@simpsons.com", "online": false },
{ 'name': 'Homer', "email": "home@simpsons.com", "online": true },
{ 'name': 'Marge', "email": "marge@simpsons.com", "online": true }
]
},
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Online', dataIndex: 'online' }
],
width: 400,
renderTo: 'output'
});
});
.x-grid-row.user-online .x-grid-cell
{
background-color: #9fc;
}
.x-grid-row.user-offline .x-grid-cell
{
background-color: #ffc;
}
How To Change Grid Column Background Color
Ext.onReady(function () {
Ext.widget('grid', {
title: 'Users',
store: {
fields: ['name', 'email', 'online'],
data: [
{ 'name': 'Lisa', "email": "lisa@simpsons.com", "online": true },
{ 'name': 'Bart', "email": "bart@simpsons.com", "online": false },
{ 'name': 'Homer', "email": "home@simpsons.com", "online": true },
{ 'name': 'Marge', "email": "marge@simpsons.com", "online": true }
]
},
columns: [
{ header: 'Name', dataIndex: 'name', tdCls: 'custom-column' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Online', dataIndex: 'online' }
],
width: 400,
renderTo: 'output'
});
});
.x-grid-row .custom-column
{
background-color: #ffc;
}
ExtJS 4.1 Grid Infinite Scroll In MVC
// /scripts/app/model/User.js
Ext.define('AM.model.User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'email']
});
// /scripts/app/store/Users.js
Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',
autoLoad: true,
remoteSort: true,
buffered: true,
pageSize: 100,
proxy: {
type: 'ajax',
url: '/postdata/list',
limitParam: 'size',
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
}
});
// /scripts/app/view/user/List.js
Ext.define('AM.view.user.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: 'All Users',
store: 'Users',
initComponent: function () {
this.columns = [
{ header: 'Id', dataIndex: 'id', width: 50 },
{ header: 'Name', dataIndex: 'name', flex: 1 },
{ header: 'Email', dataIndex: 'email', flex: 1 }
];
this.callParent(arguments);
}
});
// /scripts/app/controller/Users.js
Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
stores: [
'Users'
],
models: [
'User'
],
views: [
'user.List'
],
init: function () {
}
});
// /scripts/app/app.js
Ext.Loader.setConfig({ enabled: true });
Ext.application({
name: 'AM',
appFolder: 'scripts/app',
controllers: [
'Users'
],
launch: function () {
Ext.widget('userlist', {
title: 'User List',
width: 600,
height: 400,
renderTo: 'output'
});
}
});