Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
var user = function(){
var recordInfo, sm, cm, store;
var userGird;
var record_start;
return{
init : function(){
record_start = 0;
recordInfo = this.createRecord();
sm = this.createCheckSM();
cm = this.createColumModel();
this.createStore();
userGird = this.createUserGrid();
userGird.render('usergrid');
store.load({params:{start:0,limit:50}});
this.userEdit();
},
createRecord : function(){
var recordInfoConfig = [
{name: 'viewid', type: 'int'},
{name: 'fsName', type: 'string'},
{name: 'winName', type: 'string'},
{name: 'unitName', type: 'string'},
{name: 'declarerName', type: 'string'},
{name: 'glideNo', type: 'string'},
{name: 'accepter', type: 'string'}
];
var tmprecordInfo = Ext.data.Record.create(recordInfoConfig);
return tmprecordInfo;
},
createCheckSM : function(){
var tmpsm = new Ext.grid.CheckboxSelectionModel({singleSelect:false});
return tmpsm;
},
createColumModel : function(){
var cmConfig = [
new Ext.grid.RowNumberer({
header : '序号',
width : 40,
renderer:function(value,metadata,record,rowIndex){
return record_start + 1 + rowIndex;
}
}),
sm,
{header:'编号',dataIndex:'viewid',sortable:true},
{header:'中心项目名称',dataIndex:'fsName',sortable:true},
{header:'窗口名称',dataIndex:'winName',sortable:true},
{header:'单位名称',dataIndex:'unitName',sortable:true},
{header:'申请人',dataIndex:'declarerName',sortable:true},
{header:'办件流水号',dataIndex:'glideNo',sortable:true},
{header:'受理人',dataIndex:'accepter',sortable:true}
];
var tmpcm = new Ext.grid.ColumnModel(cmConfig);
return tmpcm;
},
createStore : function(){
var storeConfig = {
proxy: new Ext.data.DWRProxy(FocusItemAction.getItemsList, true),
reader: new Ext.data.ListRangeReader({
totalProperty: 'totalSize',
root: 'data',
id: 'id'
},
recordInfo),
remoteSort: true
};
store = new Ext.data.Store(storeConfig);
store.on('beforeload', function() { //Ext.data.JsonStore读入数据之前的事件,store不需要在写baseParams,因为会覆盖掉. (每次调用都载入此函数,'load'则第一次不调用外,其余都调用).
this.baseParams = {
queryvalue : Ext.getCmp('searchField').getValue(),
queryvalue1 : Ext.getCmp('searchWinField').getValue()
// queryvalue : queryValues//全局变量
};
});
},
createUserGrid : function(){
var gridConfig = {
autoScroll:true,
//autoHeight: true,
height: 500,
bodyStyle:'width:100%',
viewConfig: {
forceFit:true
},
stripeRows:true,
//enableDragDrop: true,
store: store,
cm: cm,
sm : sm,
tbar:['-',{text:'增加', iconCls:'add',handler:function(){window.location.href = 'item_add.jsp';}},'-',
{text:'修改', iconCls:'edit',handler:this.userEdit},'-',
{text:'删除',iconCls:'del',handler:this.userDelete},'-',
{text:'项目名称:'},'-',
{id:'searchField',xtype:'textfield',
listeners : {specialKey : function(field, e) {
if (e.getKey() == Ext.EventObject.ENTER) {//响应回车
user.userSearch();
}
}}},'-',
{text:'窗口名称:'},'-',
{id:'searchWinField',xtype:'textfield',
listeners : {specialKey : function(field, e) {
if (e.getKey() == Ext.EventObject.ENTER) {//响应回车
user.userSearch();
}
}}},'-',
{text:'查询',iconCls:'search', xtype:'button', handler:this.userSearch},'-'],
listeners : {
'render': function(){
var mask = Ext.get('loading');
if(mask) mask.remove();
//tb.render(this.tbar); // add tbar
}
},
bbar: new Ext.PagingToolbar({
pageSize: 50, // 设置一页显示多少条记录
store: store,
displayInfo: true,
displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
emptyMsg: '没有数据',
doLoad : function(start){
record_start = start;
var o = {}, pn = this.paramNames;
o[pn.start] = start;
o[pn.limit] = this.pageSize;
this.store.load({params:o});
}
})
};
var grid = new Ext.grid.GridPanel(gridConfig);
return grid;
},
renderWindow : function(value) {
if (value == '1') {
return '<span style="color:#00006F">工商窗口</span>';
}else{
return '<span style="color:green;font-weight:bold;">""</span>';
}
},
userSearch : function(){
var s = {};
s['start'] = 0;
s['limit'] = 20;
// formMap=dwr.util.getValues("itemForm");
// FocusItemAction.getItemsList(formMap);
// alert(formMap);
// s['queryvalue']=values;
store.load({params:s});
},
userDelete : function(){
var msg = new Array();
var cell = userGird.getSelectionModel().each(function(rec){
msg.push(rec.get('viewid'));
Ext.MessageBox.confirm('提示','确定要删除中心项目吗!',function(id){
if(id == 'yes'){
FocusItemAction.focusItemdelete(msg,function(isFlag){
// alert("==== "+msg);
if(isFlag == 'deleteSuc'){
// Ext.MessageBox.alert('提示', '用户已经被停用!');
store.reload(); // 重新定位刷新数据
}
// else if(isFlag == 'deleteFail') Ext.MessageBox.alert('提示', '您还没有选择要删除的中心项目,请选择!');
// window.location.href="item_index.jsp";
});
}
});
},this);
},
userEdit : function(){
var userArray = new Array();
// 获取选中的记录
/*var records = userGird.getSelectionModel().getSelections();
alert(records);
if(records.length > 1 || records.length == 0) {
Ext.MessageBox.alert('提示', '\n一次选择修改一条记录!\n');
return;
}
*/
alert("-----------------");
var records = userGird.getSelectionModel().getSelected();
alert(records +"----- "+records.data.viewid);
FocusItemAction.focusItem_update(records.data.viewid);
setTimeout(tt,3000);
//window.location.href="item_index.jsp";
//window.location.href = 'item_update.jsp?data=' + records.data.id;
}
}
}();
Ext.onReady(user.init,user,true);
/* 添加中心项目*/
function itemAdd(){
var number=document.getElementById("numberItem").value;
FocusItemAction.focusItem_add(number);
Ext.MessageBox.alert('提示', '\n请稍等,数据正在加载中......\n');
setTimeout(tt,3000);
}
function item_update(){
var userArray = new Array();
// 获取选中的记录
alert("records");
var records = userGird.getSelectionModel().getSelections();
alert(records);
if(records.length > 1 || records.length == 0) {
Ext.MessageBox.alert('提示', '\n一次选择修改一条记录!\n');
return;
}
var records = userGird.getSelectionModel().getSelected();
FocusItemAction.focusItem_update(records.data.viewid);
setTimeout(tt,3000);
}
function tt(){
window.location.href="item_index.jsp";
}
/* 修改中心项目*/
function itemupdate(){
var url=document.URL;
alert(url);
var id=url.split("=")[1];
FocusItemAction.focusItem_update(id);
window.location.href="item_index.jsp";
}
function getFormValue(){
formMap=dwr.util.getValues("itemForm");
var values="where 1=1";
for(var value in formMap){
alert(formMap[value]);
if(formMap[value]!=""&&formMap[value]!=-1){
values+=" and oiv.id."+value+" like '%"+formMap[value]+"%'";
}
}
queryValues=values;
user.userSearch(values);
}
这是个JS文件,怎么在页面中直接调用里面的userEdit方法,使用刷新就能修改数据。
5 个解决方案
#1
声明一个全局变量,将这个方法的引用传给他,然后通过它调用,你试一下可以吗?不过,我感觉你写的这个Extjs代码很水。。。
#2
好长好长,帮顶
#3
顶一下。。。。。。
#4
好长好长,帮顶
#5
代码是很长。。。 我解决这个问题的方式是:
success:function(f,v)里面给修改的当前行record赋值,然后formPanel.form.loadRecord(record);刷新就能修改数据
success:function(f,v)里面给修改的当前行record赋值,然后formPanel.form.loadRecord(record);刷新就能修改数据
#1
声明一个全局变量,将这个方法的引用传给他,然后通过它调用,你试一下可以吗?不过,我感觉你写的这个Extjs代码很水。。。
#2
好长好长,帮顶
#3
顶一下。。。。。。
#4
好长好长,帮顶
#5
代码是很长。。。 我解决这个问题的方式是:
success:function(f,v)里面给修改的当前行record赋值,然后formPanel.form.loadRecord(record);刷新就能修改数据
success:function(f,v)里面给修改的当前行record赋值,然后formPanel.form.loadRecord(record);刷新就能修改数据