Please help. I am using extjs. Currently my editable grid has two buttons ("Update" and "Cancel") I need to add new button "Save and Next" (Saves the current row and makes next row editable) in the editable grid. Can someone please help me achieve this.
Asked
Active
Viewed 1,607 times
1
-
can you share your code? – JGV Jun 15 '15 at 12:14
-
Sorry code sharing is not allowed. But I have used Sencha website to construct the application. – umesh motwani Jun 15 '15 at 12:34
-
http://www.sencha.com/products/download/?wb48617274=34026C85 – umesh motwani Jun 15 '15 at 12:37
3 Answers
2
If you share your code then i can give best answer to you. I have written code for editing row when click on button (that is in grid as a actioncolumn). You can write code for saving data where you want before editing code.
Ext.application({
name: 'Fiddle',
launch: function() {
var studentStore = Ext.create('Ext.data.Store', {
autoLoad: 'false',
fields: [
{name: 'studentId'},
{name: 'name'},
{name: 'age'}
],
data:[
{'studentId': 1, 'name': 'Puneet', 'age': 25}
]
});
cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
Ext.create('Ext.window.Window', {
title: 'Row Editing Grid',
height: 400,
width: 400,
items: [{
xtype: 'grid',
height: 400,
store:studentStore,
plugins: [cellEditing],
columns:[
{
xtype: 'actioncolumn',
items:[
{
text:'Add New Row',
tooltip: 'Add Row',
icon: 'add.png',
handler: function(grid, rowIndex, colIndex){
grid.store.add({});
var rowIndex = grid.store.data.items.length - 1;
cellEditing.startEdit(rowIndex,1);
}
}
]
},
{
header: 'StudentId',
dataIndex: 'studentId',
editor:{
xtype: 'textfield'
}
},
{
header: 'Name',
dataIndex: 'name',
editor:{
xtype: 'textfield'
}
},
{
header: 'Age',
dataIndex: 'age',
editor:{
xtype: 'textfield'
}
}
]
}]
}).show();
}
});

Puneet Chawla
- 5,729
- 4
- 16
- 33
-
Hello Puneet. Thanks for your help. I am really sorry that I am not able to share the code. But I am looking for an implementation as suggested by Jan S in the below comment. Can you please provide some implementation of what Jan has suggested. – umesh motwani Jun 16 '15 at 14:33
-
I am facing error while posting comments and hence not able to provide hyperlink also sometimes. – umesh motwani Jun 16 '15 at 14:34
-
Hello Umesh. Thanks to you also for sharing your thoughts with me. I checked Jan S code RowEditorButtons. It's almost same as i provided you above. Actually when you click on button (that is in grid), currently it will save you data in store and next row will be start editing. If you can't share code then share with me by snapshot (if you can) for better understanding, so that i can provide you exactly solution that you want. I think, Jan S will explain better or give you exactly code that you want. If you have any doubts then discuss with me. I will solve it out surely. – Puneet Chawla Jun 16 '15 at 16:59
-
Hello Puneet. I have added a comment which is a link to how my grid looks like. The problem is that editable grid which I have shared in above link has 2 buttons (Update and Cancel) and I want an extra button (Save and Next). This extra button will save the data in the current row and make the next row editable.Please let me know if I can provide more information to make my requirement clear. – umesh motwani Jun 17 '15 at 04:55
-
Also I tried to add image and it gives an error saying that I need 10 reputations to post an image.I am not sure of this error as well :( – umesh motwani Jun 17 '15 at 04:59
-
Also Puneet, I am new to extjs. Please excuse me if I am wrong somewhere. I tried to run the code you gave above on below link and it doesnot seem to work. Please correct me if I am wrong. https://fiddle.sencha.com/#home – umesh motwani Jun 17 '15 at 06:46
-
Hello Umesh, Give me some time. I will give you code after adding your requirement in this below code. dev.sencha.com/ext/5.1.0/examples/grid/row-editing.html – Puneet Chawla Jun 17 '15 at 07:44
-
-
Umesh. You have to till today night. I will send you surely. It's easy for me to do but i am very busy now. Sorry for delay. – Puneet Chawla Jun 17 '15 at 09:09
-
1
I have updated my previous code to make it as you want. Now there is one button on top bar of grid. When you click on it, it will save your current row and next row will be editable. Now it's working correctly as you want. Still if you get any problem, then share with me, i will solve it out.
Ext.application({
name: 'Fiddle',
launch: function() {
var studentStore = Ext.create('Ext.data.Store', {
autoLoad: 'false',
fields: [
{name: 'studentId'},
{name: 'name'},
{name: 'age'}
],
data:[
{'studentId': 1, 'name': 'Puneet', 'age': 25}
]
});
cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
Ext.create('Ext.window.Window', {
title: 'Row Editing Grid',
height: 400,
width: 400,
items: [{
xtype: 'grid',
id: 'rowEditingGrid',
height: 400,
store:studentStore,
plugins: [cellEditing],
tbar: [{
text: 'Save',
iconCls: 'employee-add',
handler: function(){
var grid = Ext.getCmp('rowEditingGrid');
grid.store.add({});
var rowIndex = grid.store.data.items.length - 1;
cellEditing.startEdit(rowIndex,0);
}
}],
columns:[
{
header: 'StudentId',
dataIndex: 'studentId',
editor:{
xtype: 'textfield'
}
},
{
header: 'Name',
dataIndex: 'name',
editor:{
xtype: 'textfield'
}
},
{
header: 'Age',
dataIndex: 'age',
editor:{
xtype: 'textfield'
}
}
]
}]
}).show();
}});

Puneet Chawla
- 5,729
- 4
- 16
- 33
-
Hi Puneet. Appreciate your help. But when I try to run this I noticed that After clicking on Save it goes to next row and doesn't make it editable. You have to again double click on that row. Also I would be thankful if i can get this on the grid I have used (link that I shared). So please if you can use that code it would be more helpful for me – umesh motwani Jun 17 '15 at 13:54
-
Hi Umesh. I have checked above code many times in "Sencha Fiddler". It works properly as you want. When click on save button, it saves current now and next row start editing. Just copy above code. Open this link - https://fiddle.sencha.com/#home and paste all code. It will proper work. – Puneet Chawla Jun 17 '15 at 14:56
-
Hi Puneet. Pardon me, actually I was running the code in some other version of Mozilla. But now i tried to run it on latest browser and it is running fine. But there is something i would like to highlight. 1) the save button creates a new row. It doesnot go on next editable row. If you create 5 records and double click on 2nd row to edit and then click save it will create new row. I need that the button should make the next row editable. – umesh motwani Jun 17 '15 at 17:27
-
Also Puneet I am using Ext.grid.plugin.RowEditing and this gives me Update and cancel button. Here I want an extra button Save and Next which saves the current row which i am editing and makes the next row editable. Thanks for your help again :) – umesh motwani Jun 17 '15 at 17:29
-
So, i need to add an extra button in RowEditing plugin (which is providing two button Update and cancel). It means when you edit row or click on row, it will show you three buttons - Update, Cancel, Save. If i am wrong then please send me snapshot otherwise I will do it but it will take some time, i will give you code after completing this as soon as possible. – Puneet Chawla Jun 18 '15 at 00:46
-
Jan S has posted code, that i correct properly, as you want. When click on Save & next, it just move on next row and start editing. Good efforts by Jan S. – Puneet Chawla Jun 18 '15 at 00:52
-
Hello Puneet. Yes I think that will solve my purpose. Thanks a lot for your help too :) – umesh motwani Jun 18 '15 at 17:24
-
-
Puneet. I also have a doubt regarding the modal window in extjs that is like a pop up window and it disables the parent screen Can you help me with that? – umesh motwani Jun 19 '15 at 04:08
0
if you don't mind to get your hands dirty and override ExtJS code of the RowEditorButtons. look at the constructor and use Ext.define with override to add another button.
Here is a working example:
Ext.define('CompanyName.grid.RowEditorButtons', {
override: 'Ext.grid.RowEditorButtons',
constructor: function(config) {
var me = this,
rowEditor = config.rowEditor,
editPlugin = rowEditor.editingPlugin;
me.callParent(arguments);
if(editPlugin.saveAndNextBtn){
me.insert(0,{
cls: Ext.baseCSSPrefix + 'row-editor-update-button',
itemId: 'next',
handler: editPlugin.saveAndNext,
text: 'Save and next',
disabled: rowEditor.updateButtonDisabled
});
}
}
});
Ext.define('CompanyName.grid.plugin.RowEditing', {
override: 'Ext.grid.plugin.RowEditing',
saveAndNext: function(button){
var ctx = this.context,
nextIdx = ctx.rowIdx + 1,
nextRec = ctx.store.getAt(nextIdx);
this.completeEdit();
this.startEdit(nextRec);
}
});
Ext.create('Ext.grid.Panel', {
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: 'homer@simpsons.com', phone: '555-222-1244' },
{ name: 'Marge', email: 'marge@simpsons.com', phone: '555-222-1254' }
]
},
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'}
],
plugins: {
ptype: 'rowediting',
clicksToEdit: 1,
saveAndNextBtn: true // enable it here
},
height: 200,
width: 400,
renderTo: Ext.getBody()
});

jansepke
- 1,933
- 2
- 18
- 30
-
Hello Jan. Thanks for your input. I would be thankful to youif you can show me a demo code or example for the implementation part. – umesh motwani Jun 16 '15 at 14:35
-
-
Hello Jan. I think this is what I wanted it. Thanks a lot for your help. I will implement this in my code now :) – umesh motwani Jun 18 '15 at 17:24
-
Sure. But it does not help me. :( as I am using Ext 4.2 nextIdx = ctx.rowIdx + 1 is not working in that :( – umesh motwani Jun 19 '15 at 10:05
-
ok, thought you were using ext5. add a `debugger` statement and have a look what things are in ctx. maybe you find something that looks like a row index ;) – jansepke Jun 20 '15 at 15:31