[英]Get Element value in EXTjs GRID
如何在GRID面板中获取记录字段的值? 我有下一个代码:
var gridTablaConsulta = Ext.create('Ext.grid.GridPanel', {
title:'Consulta Tabla lotes',
store: storeTabla,
columns: [
Ext.create('Ext.grid.RowNumberer'),
{text: "NRBE", width: 60, sortable: true, dataIndex: 'NRBE'},
{text: "APLIC", width: 60, sortable: true, dataIndex: 'APLIC'},
{text: "FORM", width: 60, sortable: true, dataIndex: 'FORM'},
{text: "VERFOR", width: 60, sortable: true, dataIndex: 'VERFOR'},
{text: "FECLOT", width: 60, sortable: true, dataIndex: 'FECLOT'},
{text: "HORLOT", width: 60, sortable: true, dataIndex: 'HORLOT'},
{text: "TIPPAPLO", width: 60, sortable: true, dataIndex: 'TIPPAPLO'},
{text: "TAMPAP", width: 60, sortable: true, dataIndex: 'TAMPAP'},
{text: "FECINIIM", width: 60, sortable: true, dataIndex: 'FECINIIM'},
{text: "FECINIOB", width: 60, sortable: true, dataIndex: 'FECINIOB',editor:{xtype:'textfield', allowBlank:true}},
{text: "ESTLOT", width: 60, sortable: true, dataIndex:'ESTLOT',editor:{xtype:'textfield', allowBlank:true}},
{text: "TOTPAGGE", width: 60, sortable: true, dataIndex: 'TOTPAGGE'},
{text: "TOTPAGIM", width: 60, sortable: true, dataIndex: 'TOTPAGIM'},
{text: "DESLOT", width: 60, sortable: true, dataIndex: 'DESLOT'},
{text: "TIPDIF", width: 60, sortable: true, dataIndex: 'TIPDIF'},
{text: "DIADIF", width: 60, sortable: true, dataIndex: 'DIADIF'},
{text: "FECALT", width: 60, sortable: true, dataIndex: 'FECALT'},
{text: "FECMOD", width: 60, sortable: true, dataIndex: 'FECMOD'},
{text: "TERMOD", width: 60, sortable: true, dataIndex: 'TERMOD'},
{text: "HORMOD", width: 60, sortable: true, dataIndex: 'HORMOD'}
],
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2
})
],
listeners: {
beforeedit: {
scope: this,
fn: function(e, context2){
var record2= context2.record;
var recordData2=record2.getData();
alert(JSON.stringify(recordData2));
}
},
edit: function(e, context){
var record = context.record;
var recordData = record.getData();
recordData.Funcionalidad = 'Modificar';
alert(JSON.stringify(recordData));
Ext.Ajax.request({
url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
}
}
});
我希望当我显示网格并在寄存器中脉动时,我可以评估“ ESTLOT”字段的值,然后我将根据先前的值更改该值。
我的问题是,我只知道谁能获得属于该寄存器的所有字段,但我只希望ESTLOT值将该值传递给编辑函数,在此我将对该值进行评估。
谢谢大家,我需要很多帮助。
编辑2:
listeners: {
beforeedit: function(editor, e, eOpts) {
var grid = Ext.getCmp('gridTabla'); // or e.grid
var hoy = new Date();
dia = hoy.getDate();
if(dia<10)
{
dia=String("0"+dia);
}
mes = hoy.getMonth();
if(mes<10)
{
mes=String("0"+mes);
}
anio= hoy.getFullYear();
fecha_actual = String(anio+""+mes+""+dia);
//alert(fecha_actual);
var mola = e.record.data.ESTLOT;
alert(mola);
if (e.record.data.ESTLOT === '02') {
if (e.record.data.FECMOD === fecha_actual)
{
e.cancel = false; //permite
}
else{
e.cancel = true;
}
} else
{
e.cancel = false; //permite
}
},
edit: function(e, context){
var record = context.record;
var recordData = record.getData();
recordData.Funcionalidad = 'Modificar';
alert(JSON.stringify(recordData));
Ext.Ajax.request({
url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
}
}
});
现在我想将beforeedit中的var =“ mola”传递给编辑以进行最后的验证
编辑3个新代码和失败
listeners: {
beforeedit:
function preditar(editor, e, eOpts, mola) {
var grid = Ext.getCmp('gridTabla'); // or e.grid
var hoy = new Date();
dia = hoy.getDate();
if(dia<10)
{
dia=String("0"+dia);
}
mes = hoy.getMonth();
if(mes<10)
{
mes=String("0"+mes);
}
anio= hoy.getFullYear();
fecha_actual = String(anio+""+mes+""+dia);
//alert(fecha_actual);
var mola = e.record.data.ESTLOT;
//alert(mola);
editar(mola);
if (e.record.data.ESTLOT === '02') {
if (e.record.data.FECMOD === fecha_actual)
{
e.cancel = false; //permite
}
else{
e.cancel = true; //mo permite
}
} else
{
e.cancel = false; //permite
}
},
edit:
function editar(e, context, mola){
var record = context.record;
var recordData = record.getData();
var mola2= mola;
alert(mola2);
recordData.Funcionalidad = 'Modificar';
//alert(JSON.stringify(recordData));
Ext.Ajax.request({
url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
}
}
});
它说“记录是空的,它不是对象”,这里是这样的:var record = context.record;
再次感谢。
Sencha: beforeEdit
e:Object具有以下属性的编辑事件:
值 -该字段的值被编辑。
listeners: {
beforeedit: {
scope: this,
fn: function(e, context2){
if(e.value=="ESTLOT"){
alert("value: " + e.value);
}
}
},
...
}
编辑:
我不太了解您想在哪里获取值,但是在控制器上还有另一种情况:
接球赛事:
'gridView column[action=columnActionName]' : {
click : me.funcitonInspect
},
功能:
funcitonInspect : function(grid,el,rowIndex){
var grid = Ext.ComponentQuery.query('grid')[0];
var selection = grid.getSelectionModel();
if(selection.hasSelection()){
var modeloSelected = selection.getLastSelected();
if(modeloSelected.data.NameField=="ESTLOT"){
...
}
}
},
EDIT2: 使用FireEvent
也许您可以在beforeEdit上执行“ fireevent”:
this.fireEvent('edit', e, context);
编辑3:
尝试用以下方法获取值:var record = e.record; 第二个参数是eOpts(选项对象)-请参阅下一个说明: sencha doc
例:
edit:
function editar(e, context, mola){
var record = e.record;
...
}
},
这是完整的解决方案。 谢谢大家
listeners: {
beforeedit:
function preditar(editor, e, eOpts) {
var grid = Ext.getCmp('gridTabla'); // or e.grid
var hoy = new Date();
dia = hoy.getDate();
if(dia<10)
{
dia=String("0"+dia);
}
mes = hoy.getMonth();
if(mes<10)
{
mes=String("0"+mes);
}
anio= hoy.getFullYear();
fecha_actual = String(anio+""+mes+""+dia);
e.record.beforeEditESTLOT = e.record.data.ESTLOT;
if (e.record.data.ESTLOT === '02') {
if (e.record.data.FECMOD === fecha_actual)
{
e.cancel = false; //permite probar mañana con cambio fecha
}
else{
alert("Solo puedes modificar este estado en lotes modificados en el día actual");
e.cancel = true; //no permite
}
} else
{
e.cancel = false; //permite
}
},
edit:
function editar(e, context){
var record = context.record;
var recordData = record.getData();
recordData.Funcionalidad = 'Modificar';
var modificado = record.modified.ESTLOT; //valores anteriores
//alert(modificado);
//var nuevo = recordData.ESTLOT;
//var cadena = JSON.stringify(recordData);
//alert(cadena);
var prueba = context.record.data.ESTLOT;//valores nuevos
//alert(prueba);
if ((modificado==='06')||(modificado==='03'))
{
if ((prueba==='01')||(prueba==='02')||(prueba==='03')||(prueba==='06'))
{
Ext.Ajax.request({
//url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
alert("Modificacion realizada correctamente");
}
else
{
alert("Si el valor anterior de estado de lote es 06 o 03 no puede pasar a valer 04 o 05");
}
}
if ((modificado==='04')||(modificado==='05'))
{
if ((prueba==='02')||(prueba==='04')||(prueba==='05')||(prueba==='06'))
{
Ext.Ajax.request({
//url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
alert("Modificacion realizada correctamente");
}
else
{
alert("Si el valor anterior de estado de lote es 04 o 05 no puede pasar a valer 01 o 03 o en blanco");
}
}
if(modificado==='01')
{
if ((prueba==='02')||(prueba==='03')||(prueba==='04')||(prueba==='05')||(prueba==='06'))
{
Ext.Ajax.request({
//url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
alert("Modificacion realizada correctamente");
}
else
{
alert("Insertad un valor valido");
}
}
if(modificado===' ')
{
if ((prueba==='02')||(prueba==='01')||(prueba==='03')||(prueba==='04')||(prueba==='05')||(prueba==='06'))
{
Ext.Ajax.request({
//url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
method: 'POST',
// merge row data with other params
params: recordData
});
alert("Modificacion realizada correctamente");
}
else
{
alert("Insertad un valor valido");
}
}
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.