How to create Editable gridpanel - extjs

I have created a grid. I just want to know how to make it editable.Though I can find many examples over here.I am not being able to understand it as I am new to it. Can you please tell me in simple way?

You can use cell or rowedit functions in grid. The following examples show how you can do.
Cell Edit Sample
// Cell Edit example
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
/**
* here is the important part
* you should define each or single column 'editor' property
* then specify the 'plugins' that you want to use, here is 'CellEditing'
* as you might guess, all definitions appear in the grid definition
*/
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Row Edit Sample
// Row Edit Sample
// the difference with cell edit, just showing an editor screen to change something
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":"home#simpsons.com", "phone":"555-222-1244"},
{"name":"Marge", "email":"marge#simpsons.com", "phone":"555-222-1254"}
]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
/**
* Same aspect
* you should define 'editor' property
* if you don't define editor property for a colum,
* you can't change anyhthing for that column
*/
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'}
],
selType: 'rowmodel',
// here is the plugin definition
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});

Related

How to change default title of errorSummary from "Errors" to something else in EXTJs

How to customize errorSummary in Extjs? The default title for errorSummary is "Errors"(screenshot attached for reference), is there any way to change it to something else?
Image
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":"home#simpsons.com", "phone":"555-222-1244"},
{"name":"Marge", "email":"marge#simpsons.com", "phone":"555-222-1254"}
]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'}
],
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1,
errorSummary:true,
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1,
errorsText:'test',
errorSummary:true
})
],
If you want to change it globally,We can override the editing plugin by using below code.
Ext.define('OverridedRowEditing',{
override: 'Ext.grid.plugin.RowEditing',
config: {
errorsText: 'Test'
}
});

Not able to perform left arrow and right arrow key operation in extjs grid textfiled column

var tmp= "<table border='0' cellspacing='0' cellpadding='0'><tr>";
tmp += "<td height='35' align='left' valign='middle' ><input name='' id='' type='text'></td>";
tmp += "</tr></table>";
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{"name":'KK', "email":"lisa#simpsons.com", "phone":tmp},
{"name":'AB', "email":"bart#simpsons.com", "phone":tmp},
{"name":'FGF', "email":"home#simpsons.com", "phone":tmp},
{"name":'dfsd', "email":"marge#simpsons.com", "phone":tmp}
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name'},
{header: 'Email', dataIndex: 'email', flex:1},
{header: 'Phone', dataIndex: 'phone'}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
In the above code for phone no field i added html textbox. If i am pressing left/rigth keys in keyboard it is shifting to left cell or right cell instead of moving cursor in text filed. can any one give the solution for this one? I am using extjs 4.0.7.
There are events on the grid catching the keypress.
Instead of trying to "insert" html code inside the value of the cell, why don't you just use the default "cellediting" plugin, as specified in the original example?
Just move the editor block from the email column to the phone column:
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name'},
{header: 'Email', dataIndex: 'email', flex:1},
{header: 'Phone', dataIndex: 'phone',
editor: {
xtype:'textfield',
allowBlank:false
}
}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
This works for me, one you click once (or twice if you change the clicksToEdit from 1 to 2), you are now in edit mode (textfield by default) and you can then "navigate" your phone number by using key arrows.
With this solution, no need for the "tmp" variable (html code) you create, hence no event race.

Filter for grid

Ext.define('TPL.view.Book', {
extend: 'Ext.grid.Panel',
alias: 'widget.book',
title: 'Books',
store: 'Book',
header: false,
stripeRows: true,
initComponent: function() {
this.columns = [
{header: 'Id', dataIndex: 'id', flex: 1},
{header: 'Author', dataIndex: 'author', width: 50, flex: 0},
{header: 'Price', dataIndex: 'price', width: 50, flex: 0},
];
this.callParent(arguments);
}});
And in header (column - 'Author') i am want make filter - so when a user enters a word into the filter, then outputs the result in the table (filter should be independent case for words). How make this? thanks
about this:
To use filters on the grid panel you have to do the following:
add 'Ext.ux.grid.FiltersFeature' to the 'requires' property of your grid,
add filters as a feature to your grid panel:
features: [
{
ftype: 'filters',
local: true
}
]
and finally, mark the columns you which to have the filter using the property 'filter':
{
xtype: 'gridcolumn',
filter: {
type: 'string'
}
...
}

RowExpander not working on grid - Ext JS 4.1.1

I have the panel here that displays fine until i try to implement the rowexpander plugin:
Ext.define('AM.view.userlist.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: '<center>Results</center>',
store: 'User',
collapsible: true,
plugins: [{
ptype: 'rowexpander',
id: 'rowexpander',
rowBodyTpl : [
'<p>Name <b>{name}</b></p>',
'<p><b>Address {address}</b></p>'
]
}],
collapsible: true,
animCollapse: false,
initComponent: function() {
this.columns = [
{header: 'ID', dataIndex: 'id', flex: 4, tdCls: 'grid_cell'},
{header: 'Name', dataIndex: 'name', flex: 4, tdCls: 'grid_cell'},
{header: 'Address', dataIndex: 'address', flex: 3, tdCls: 'grid_cell'},
{header: 'Phone', dataIndex: 'phone', flex: 3, tdCls: 'grid_cell'}
];
this.callParent(arguments);
//remaining code...
When i attempt to add the plugin, I get this exception:
TypeError: name is undefined
I'm not sure why I can't get it to work. Any ideas?
Try:
...
requires: [
'Path.to.RowExpander'
],
...

Ext Js combobox value after onchange is value instead of label

Just getting frustrated by something that should be an easy fix, but I'm too simple minded to see it :)
I'm having a grid where 1 column is a combobox. The thing works just fine and the correct value is beeing sent through my ajax request, but after I edited the grid row, the combobox disappread and the value that comes into place is not the label, but the value.
editor: new Ext.form.field.ComboBox({
typeAhead: true,
lazyRender: true,
store: new Ext.data.ArrayStore({
fields: ['contact', 'contactLabel'],
data: [
[1,'Jan'],
[2,'Jeroen'],
[3,'Mattijs'],
[4,'Sven'],
[5,'Thomas'],
[6,'Yoran']
]
}),
valueField: 'contact',
displayField: 'contactLabel',
hiddenName: 'contact'
})
So what happens is that when I change the combobox to i.e.. "Thomas", the value of the cell becomes "5", instead of "Thomas". I thought that defining value/display fields would make a difference, but it does not.
Anyone that knows the answer?
I am not quite sure if I got you right. If so you will need a renderer for that. I guess the example below the code snipped should show you if you are meaning such a case.
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
See this full working example for both (cellEditing + rowEditing) JSFiddle ()
Here's the complete code
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone', 'id'],
data:{'items':[
{"name":"Lisa", "email":"lisa#simpsons.com", "phone":"555-111-1224","id": 0},
{"name":"Bart", "email":"bart#simpsons.com", "phone":"555-222-1234","id": 1},
{"name":"Homer", "email":"home#simpsons.com", "phone":"555-222-1244","id": 2},
{"name":"Marge", "email":"marge#simpsons.com", "phone":"555-222-1254","id": 3}
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
// the combo store
var store = new Ext.data.SimpleStore({
fields: [ "value", "text" ],
data: [
[ 0, "Option 0" ],
[ 1, "Option 1" ],
[ 2, "Option 2" ],
[ 3, "Option 3" ]
]
});
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: 'cell'
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: 'row'
});
html
<div id="cell"></div>
<div id="row"></div>
Try:
data: [
{contact: 1, contactLabel: 'Jan'},
...
]

Resources