javascript Extjs:在同一行中的另一个单元格的每次更改时更改网格单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18584733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extjs : Change grid cell value on every change of another cell in the same row
提问by Sivakumar
I am working on extjs Grid panel which has 2 columns as shown in the below fig.
我正在研究 extjs Grid 面板,它有 2 列,如下图所示。
My requirement is to change "Short Name" cell value on every change of corresponding "Task Description" cell value. I have used editor for "Task Description" column as shown below.
我的要求是在每次更改相应的“任务描述”单元格值时更改“短名称”单元格值。我已将编辑器用于“任务描述”列,如下所示。
columns: [
{
text: 'Task Description',
dataIndex: 'TaskDescription',
flex : 1.5,
editor: {
xtype : 'textarea',
allowBlank : false,
listeners : {
change : function(field, e) {
var text = field.value;
if(text.length <= 26 && !text.match(/[.:-]/)) {
if(text.length == 26) {
text = text[25]==' ' ? text : text.substring(0, text.lastIndexOf(' '));
}
//code to set short name cell value.
}
}
}
}
},
{
text: 'Short Name',
dataIndex: 'Name',
width: 130
}
]
But how can i access "Short Name" column to set it from change event function.
但是我如何访问“Short Name”列以从更改事件功能中设置它。
Please suggest me the solution.
请给我建议解决方案。
Thanks in advance.
提前致谢。
采纳答案by Sivakumar
I got solution to this problem.
我得到了解决这个问题的方法。
listeners : {
change : function(field, newValue,o ,e) {
var text = field.value;
if(text.length <= 26 && !text.match(/[.:-]/)) {
if(text.length == 26) {
text = text[25]==' ' ? text : text.substring(0, text.lastIndexOf(' '));
}
var selectedModel = this.up('grid').getSelectionModel().getSelection()[0];
selectedModel.set('Name', text);
}
}
}
回答by Dev
You can use a edit event listener and play with the record as you want. Here it is :
您可以使用编辑事件侦听器并根据需要播放记录。这里是 :
listeners: {
edit: function (editor, e, eOpts) {
var text = e.record.data.name;
console.log(text);
if (text.length <= 26 && !text.match(/[.:-]/)) {
if (text.length == 26) {
text = text[25] == ' ' ? text : text.substring(0, text.lastIndexOf(' '));
}
//code to set short name cell value.
var record = e.record;
record.set("email", text); //Here you can set the value
}
}
}
Their are many ways you can achieve the desired task.This is one way!! For reference,here is the fiddle
他们有很多方法可以实现您想要的任务。这是一种方法!!作为参考,这里是小提琴