ExtJS - Grid Cell Tool Tip - extjs

I am trying to create a tooltip for cells. Below code does that, but tooltip appears only onClick(in mozilla) and in IE tooltip appears on mouseOver but display value of last clicked cell.
I wanted a tooltip on grid in mouseOver with cells content as tooltip display value.
Please suggest any other way to achieve that. Thanks in advance.
var grid = Ext.getCmp('your_grid_id'); // Enter your grid id
initToolTip(grid); // call function
initToolTip: function(grid) {
var view = grid.view;
// record the current cellIndex
grid.mon(view, {
uievent: function(type, view, cell, recordIndex, cellIndex, e) {
grid.cellIndex = cellIndex;
grid.recordIndex = recordIndex;
}
});
grid.tip = Ext.create('Ext.tip.ToolTip', {
target: view.el,
delegate: '.x-grid-cell',
trackMouse: true,
renderTo: Ext.getBody(),
listeners: {
beforeshow: function updateTipBody(tip) {
if (!Ext.isEmpty(grid.cellIndex) && grid.cellIndex !== -1) {
header = grid.headerCt.getGridColumns()[grid.cellIndex];
columnText = grid.getStore().getAt(grid.recordIndex).get(header.dataIndex);
tip.update(columnText);
}
}
}
});

You could use renderer config for gridcolumn and inside of renderer you could return a html tag with you data-qtip based on your record what you need to show.
You can check here with working FIDDLE.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
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": "homer#simpsons.com",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: 'simpsonsStore',
columns: [{
text: 'Name',
dataIndex: 'name',
renderer: function (value, metaData, record, rowIndex, colIndex, store) {
return `<span data-qtip="This is ${value}"> ${value} </span>`;
}
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
renderTo: Ext.getBody()
});
}
});

Related

Stateful grid in ExtJs 7.3 MODERN

I don't get it, according to the manual for ExtJs 7.3 Modern it should be possible to configure a Ext.grid.Grid (https://docs.sencha.com/extjs/7.3.0/modern/Ext.grid.Grid.html#cfg-stateful).
I've added:
({
// ...
stateId: 'state-grid',
stateful: true,
// ...
});
and on the columns also added an stateId for each column and in the applications launch function I've added:
launch: function() {
Ext.state.Provider.register(new Ext.state.LocalStorage());
Ext.get(Ext.query('#appLoadingIndicator')).remove();
this.callParent(arguments);
}
But I dont get the stateful grid to work, i.e. I hide a column and then refresh the site.. the column is still visible. So does stateful work at all in ExtJs 7.3 MODERN <--- Modern not classic.
Have a look at the following self-explainable fiddle sample. It saves the width and hidden properties of the grid column:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.state.Provider.register(new Ext.state.LocalStorage());
var store = Ext.create('Ext.data.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"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}]
});
var grid = Ext.create('Ext.grid.Grid', {
title: 'Simpsons',
columns: [{
text: 'Name',
dataIndex: 'name',
stateId: 'name-column-state-id',
stateful: {
// we will state hidden and width of the column states only
hidden: true,
width: true
}
}, {
text: 'Email',
dataIndex: 'email',
stateId: 'email-column-state-id',
stateful: {
// we will state hidden and width of the column states only
hidden: true,
width: true
}
}, {
text: 'Phone',
dataIndex: 'phone',
stateId: 'phone-column-state-id',
stateful: {
// we will state hidden and width of the column states only
hidden: true,
width: true
}
}],
store: store,
layout: 'fit',
fullscreen: true
});
}
});

EXTJS 6 Grid Column Renderer Function - where do you define it?

In EXTJS 4/5 you could create an inline function which you could then use as a grid column renderer, like this
function myColumnRenderer(value, metaData, record, rowIndex, colIndex, store){
//do something with the data and return
return value;
}
and in your grid's column definition you would reference the renderer like this
columns:[
{ text: 'ColA', dataIndex: 'ColA', renderer: myColumnRenderer},
{ text: 'ColB', dataIndex: 'ColB', renderer: myColumnRenderer}
]
In EXTJS 6.5, can you still do this and if so where do you define the renderer function? In the controller, or viewModel, or elsewhere? I've tried putting the function in the controller and putting this.myColumnRenderer in the renderer of the column but it never seems to get called.
Looks like this is an option, just not sure if it's the correct way to do it
columns:[
{ text: 'ColA', dataIndex: 'ColA', renderer: function(value, metaData, record, rowIndex, colIndex, store) {
return this.getController().myColumnRenderer(value, metaData, record, rowIndex, colIndex, store);
}},
{ text: 'ColB', dataIndex: 'ColB', renderer: function(value, metaData, record, rowIndex, colIndex, store) {
return this.getController().myColumnRenderer(value, metaData, record, rowIndex, colIndex, store);
}}
]
In ExtJS 6 you can also create but inline function but instead of inline function we can create ViewController for grid or any view like below example
Ext.define('MyViewController', {
extend : 'Ext.app.ViewController',
alias: 'controller.myview',
// This method is called as a "handler" for the Add button in our view
onAddClick: function() {
Ext.Msg.alert('Add', 'The Add button was clicked');
}
});
Ext.define('MyView', {
extend: 'Ext.Panel',
controller: 'myview',
items: [{
xtype: 'button',
text: 'Add',
handler: 'onAddClick', // calls MyViewController's onAddClick method
}]
});
In this FIDDLE, I have create a demo using viewController and grid component. I hope this will help/guide you to achieve your requirement.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.define('GridController', {
extend: 'Ext.app.ViewController',
alias: 'controller.gridcntr',
//This event will fire for grid column renderer
onColRender: function (value, metaData, record, rowIndex, colIndex, store) {
console.log(value);
return value;
}
});
var store = Ext.create('Ext.data.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"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}]
});
Ext.create({
xtype: 'grid',
controller: 'gridcntr',
title: 'user data',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
width: 200,
renderer: 'onColRender'
}, {
text: 'Email',
dataIndex: 'email',
width: 250,
renderer: 'onColRender'
}, {
text: 'Phone',
dataIndex: 'phone',
width: 120,
renderer: 'onColRender'
}],
layout: 'fit',
fullscreen: true,
renderTo:Ext.getBody()
});
}
});
You can use the renderer like this ExtJs 6
columns: [
{ width:"100%", renderer: function(value,metaData,records,view) {
//your conditions
}}]

How to combine rowediting and rowexpander together correctly in extjs?

I am developing a web application in ExtJS. The application is a grid where some of the grid`s rows can be expanded to show supplementary information as a nested grid. And user can edit rows in parent grid.
But I have problems with it. The nested grid is normally rendered , but when I want to update one of the field nested grid disappear.
There is testing version of my application and some screenshots.
The Code ( below you can find screens)
Ext.onReady(function() {
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'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"
},
{
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
plugins: [{
ptype: 'rowexpander',
pluginId: 'courseListGridExpander',
expandOnDblClick: false,
selectRowOnExpand: false,
enableCaching: false,
rowBodyTpl: ['']
},
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 2,
autoCancel: false
})
],
viewConfig: {
listeners: {
expandbody: function(rowNode, record, expandbody) {
var targetId = 'SessionInstructionGridRow';
if (Ext.getCmp(targetId + "_grid") == null) {
var sessionInstructionGrid = Ext.create('Ext.grid.Panel', {
renderTo: targetId,
id: targetId + "_grid",
title: 'Nested One',
columns: [{
header: 'Halo',
flex: 1
},
{
header: 'Halo 2',
flex: 1
}
]
});
rowNode.grid = sessionInstructionGrid;
sessionInstructionGrid.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick', 'onRowFocus']);
sessionInstructionGrid.fireEvent("bind", sessionInstructionGrid, {
ClientSessionId: record.get('ClientSessionId')
});
}
},
celldblclick: function(gr, td, cellIndex, record) {
//alert("###");
}
}
},
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name',
editor: {
allowBlank: false
}
},
{
text: 'Email',
dataIndex: 'email',
flex: 1
},
{
text: 'Phone',
dataIndex: 'phone'
}
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Ext.create('Ext.button.Button', {
text: 'Hello',
handler: function() {
}
})
});
I would give the ComponentRowExpander plugin a try. It's intended to insert any component in a rowexpander - so it should work with a grid, too.

Custom drag'n'drop from a tree to a grid with Extjs5

The Ext.grid.plugin.DragDropView and Ext.tree.plugin.TreeViewDragDropView are great to allow drag'n'drop functionnality over those components but I don't want the store modification thing when I drag and drop an item.
I want custom functions, like, when I drop an item on my grid, I don't want the drag component source store to be modified and I don't want the drop component store to be modified too. I would like a function of mine to be called instead.
How to do this?
Do I need to use DragZone and DropZone instead?
You are on the right path, and looking in the right areas. The plugins that you have mentioned are exactly what you need for this purpose and provide the DragZone and DropZone functionality within.
I have written a simple example of using these plugins together, Fiddle Here.
The thing to watch out for here... If you do not want the default functionality of moving a record between stores you will likely need to run your own logic in the beforeDrop event and call the cancelDrop method, to prevent default behaviour, this is demonstrated in the fiddle and code below.
Make sure that both plugins share the same ddGroup.
Ext.application({
name: 'Fiddle',
launch: function() {
// create a very simple tree view
var treeStore = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
text: "detention",
leaf: true
}, {
text: "homework",
expanded: true,
children: [{
text: "book report",
leaf: true
}, {
text: "algebra",
leaf: true
}]
}, {
text: "buy lottery tickets",
leaf: true
}]
}
});
var gridStore = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "555-111-1224"
}, {
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "homer#simpsons.com",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
layout: 'fit',
height: 800,
width: 800,
items: [{
layout: 'border',
title: "DnD",
height: '100%',
items: [{
xtype: 'grid',
region: 'center',
store: gridStore,
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
enableDrag: false,
enableDrop: true,
ddGroup: 'myDropGroup'
},
listeners: {
beforedrop: function(node, data, overModel, dropPosition, dropHandlers) {
// Defer the handling
dropHandlers.wait = true;
// here you have the record from the treeview and can do anything you like with it.
var record = data.records[0];
Ext.MessageBox.confirm('Drop', 'Your are about to drop ' + record.get('text') + ', Are you sure?', function(btn) {
if (btn === 'yes') {
dropHandlers.processDrop();
} else {
// IMPORTANT - In this case, we want to cancel the drop as the records aren't compatible
dropHandlers.cancelDrop();
}
});
}
}
}
}, {
xtype: 'treepanel',
width: '40%',
region: 'west',
store: treeStore,
rootVisible: false,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
enableDrop: false,
ddGroup: 'myDropGroup'
}
}
}]
}]
});
}
});

How to work with celldblclick event in extjs 5

I have a requirement, in a grid panel we have 3 columns. "Name", "Age" and "Height".
So if an User will doubleclick on any cell under "Name" column then it will redirect to a new window.
`
{
xtype : 'gridpanel',
region: 'center',
height : 400,
title : 'Search Results',
id : 'searchResultsGrid',`
I know we have to use "celldblclick event, but not sure how to use it. I am using extjs version 5
This is the reference for celldblclick in extjs 5 document.
http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.panel.Table-event-celldblclick
Like that
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "555-111-1224"
}, {
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "homer#simpsons.com",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody(),
listeners: {
celldblclick: function(ctx, td, cellIndex, record, tr, rowIndex, e, eOpts) {
alert('You have clicked cell in the ' + cellIndex + ' column and ' + rowIndex + ' row')
}
}
});
}
});
https://fiddle.sencha.com/#fiddle/dbl

Resources