extjs_04_grid(弹出窗口&行编辑器 CRUD数据)
1.弹出窗口(添加。删除)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWRhbV93enM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <title>My JSP "index.jsp" starting page</title> <link rel="stylesheet" type="text/css" href="./extjs4.1/resources/css/ext-all.css">
<script type="text/javascript" src="./extjs4.1/ext-all-debug.js"></script>
<script type="text/javascript" src="./extjs4.1/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript">
Ext.onReady(function() {
// 自己定义数据模型
var myModel = Ext.define("studentInfo", {
extend : "Ext.data.Model",
fields : [ {
type : "string",
name : "stuNo"
}, {
type : "string",
name : "stuName"
}, {
type : "string",
name : "stuClass"
}, {
type : "number",
name : "chScore"
}, {
type : "number",
name : "maScore"
}, {
type : "number",
name : "enScore"
} ]
});
// 本地数据
var myData = [ [ "No1", "wangzs1", "1年级", 80, 67, 49 ], [ "No2", "wangzs2", "2年级", 65, 57, 79 ],
[ "No3", "wangzs3", "3年级", 45, 77, 59 ], [ "No4", "wangzs4", "4年级", 99, 27, 19 ],
[ "No5", "wangzs5", "5年级", 23, 97, 99 ], [ "No6", "wangzs6", "6年级", 34, 67, 99 ] ];
// 数据存储
var myStore = Ext.create("Ext.data.Store", {
model : "studentInfo",
data : myData
}); // 表格
var myGrid = new Ext.grid.Panel({
columns : [ {
xtype : "rownumberer",
text : "行号"
}, {
text : "学号",
dataIndex : "stuNo"
}, {
text : "姓名",
dataIndex : "stuName"
}, {
text : "班级",
dataIndex : "stuClass"
}, {
text : "语文",
dataIndex : "chScore"
}, {
text : "数学",
dataIndex : "maScore"
}, {
text : "英语",
dataIndex : "enScore"
} ],
store : myStore,
selModel : {
selType : "checkboxmodel"//复选框
},
multiSelect : true
//支持多选
}); // 新增panel
var addPanel = Ext.create("Ext.form.Panel", {
items : [ {
xtype : "textfield",
name : "stuNo",
fieldLabel : "学号"
}, {
xtype : "textfield",
name : "stuName",
fieldLabel : "姓名"
}, {
xtype : "textfield",
name : "stuClass",
fieldLabel : "班级"
}, {
xtype : "numberfield",
name : "chScore",
fieldLabel : "语文"
}, {
xtype : "numberfield",
name : "maScore",
fieldLabel : "数学"
}, {
xtype : "numberfield",
name : "enScore",
fieldLabel : "英语"
} ]
}); // 新增窗体
var addWindow = Ext.create("Ext.window.Window", {
title : "新增学生成绩",
closeAction : "hide",//设置该属性新增窗体关闭的时候是隐藏
width : 300,
height : 300,
items : addPanel,
layout : "fit",
bbar : {
xtype : "toolbar",
items : [ {
xtype : "button",
text : "保存",
listeners : {
"click" : function(btn) {
var form = addPanel.getForm();
var stuNoVal = form.findField("stuNo").getValue();
var stuNameVal = form.findField("stuName").getValue();
var stuClassVal = form.findField("stuClass").getValue();
var chScoreVal = form.findField("chScore").getValue();
var maScoreVal = form.findField("maScore").getValue();
var enScoreVal = form.findField("enScore").getValue();
//Ext.Msg.alert("新增的数据", "{" + stuNo + ":" + stuName + ":" + stuClass + ":" + chScore + ":"
// + maScore + ":" + enScore + "}");
var store = myGrid.getStore();
store.insert(0, {
stuNo : stuNoVal,
stuName : stuNameVal,
stuClass : stuClassVal,
chScore : chScoreVal,
maScore : maScoreVal,
enScore : enScoreVal
});
}
}
}, {
xtype : "button",
text : "取消",
listeners : {
"click" : function(btn) {
btn.ownerCt.ownerCt.close();
}
}
} ]
}
}); // 窗体
var window = Ext.create("Ext.window.Window", {
title : "学生成绩表",
width : 600,
height : 400,
items : myGrid,
layout : "fit",
tbar : {
xtype : "toolbar",
items : [ {
xtype : "button",
text : "新增",
listeners : {
"click" : function(btn) {
addPanel.getForm().reset();//新增前清空表格内容
addWindow.show();
}
}
}, {
xtype : "button",
text : "删除",
listeners : {
"click" : function(btn) {
var records = myGrid.getSelectionModel().getSelection();
myGrid.getStore().remove(records);
}
}
} ]
}
});
window.show();
});
</script> </head> <body>
添加,删除表格记录(弹窗体,适用于表字段比較多)
<br>
</body>
</html>
2.行编辑器(新增。改动)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <title>My JSP "index.jsp" starting page</title> <link rel="stylesheet" type="text/css" href="./extjs4.1/resources/css/ext-all.css">
<script type="text/javascript" src="./extjs4.1/ext-all-debug.js"></script>
<script type="text/javascript" src="./extjs4.1/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript">
Ext.onReady(function() {
// 自己定义数据模型
var myModel = Ext.define("studentInfo", {
extend : "Ext.data.Model",
fields : [ {
type : "string",
name : "stuNo"
}, {
type : "string",
name : "stuName"
}, {
type : "string",
name : "stuClass"
}, {
type : "number",
name : "chScore"
}, {
type : "number",
name : "maScore"
}, {
type : "number",
name : "enScore"
} ]
});
// 本地数据
var myData = [ [ "No1", "wangzs1", "1年级", 80, 67, 49 ], [ "No2", "wangzs2", "2年级", 65, 57, 79 ],
[ "No3", "wangzs3", "3年级", 45, 77, 59 ], [ "No4", "wangzs4", "4年级", 99, 27, 19 ],
[ "No5", "wangzs5", "5年级", 23, 97, 99 ], [ "No6", "wangzs6", "6年级", 34, 67, 99 ] ];
// 数据存储
var myStore = Ext.create("Ext.data.Store", {
model : "studentInfo",
data : myData
}); // 表格
var myGrid = new Ext.grid.Panel({
columns : [ {
xtype : "rownumberer",
text : "行号"
}, {
text : "学号",
dataIndex : "stuNo",
editor : {//用行编辑器插件须要配置该属性
xtype : "textfield"
}
}, {
text : "姓名",
dataIndex : "stuName",
editor : {
xtype : "textfield"
}
}, {
text : "班级",
dataIndex : "stuClass",
editor : {
xtype : "textfield"
}
}, {
text : "语文",
dataIndex : "chScore",
editor : {
xtype : "numberfield"
}
}, {
text : "数学",
dataIndex : "maScore",
editor : {
xtype : "numberfield"
}
}, {
text : "英语",
dataIndex : "enScore",
editor : {
xtype : "numberfield"
}
} ],
store : myStore,
selModel : {
selType : "checkboxmodel"//复选框
},
multiSelect : true,//支持多选
plugins : [ {
ptype : "rowediting",//行编辑器插件,点击2次编辑
clicksToEdit : 2
} ]
}); // 新增panel
var addPanel = Ext.create("Ext.form.Panel", {
items : [ {
xtype : "textfield",
name : "stuNo",
fieldLabel : "学号"
}, {
xtype : "textfield",
name : "stuName",
fieldLabel : "姓名"
}, {
xtype : "textfield",
name : "stuClass",
fieldLabel : "班级"
}, {
xtype : "numberfield",
name : "chScore",
fieldLabel : "语文"
}, {
xtype : "numberfield",
name : "maScore",
fieldLabel : "数学"
}, {
xtype : "numberfield",
name : "enScore",
fieldLabel : "英语"
} ]
}); // 新增窗体
var addWindow = Ext.create("Ext.window.Window", {
title : "新增学生成绩",
closeAction : "hide",//设置该属性新增窗体关闭的时候是隐藏
width : 300,
height : 300,
items : addPanel,
layout : "fit",
bbar : {
xtype : "toolbar",
items : [ {
xtype : "button",
text : "保存",
listeners : {
"click" : function(btn) {
var form = addPanel.getForm();
var stuNoVal = form.findField("stuNo").getValue();
var stuNameVal = form.findField("stuName").getValue();
var stuClassVal = form.findField("stuClass").getValue();
var chScoreVal = form.findField("chScore").getValue();
var maScoreVal = form.findField("maScore").getValue();
var enScoreVal = form.findField("enScore").getValue();
//Ext.Msg.alert("新增的数据", "{" + stuNo + ":" + stuName + ":" + stuClass + ":" + chScore + ":"
// + maScore + ":" + enScore + "}");
var store = myGrid.getStore();
store.insert(0, {
stuNo : stuNoVal,
stuName : stuNameVal,
stuClass : stuClassVal,
chScore : chScoreVal,
maScore : maScoreVal,
enScore : enScoreVal
});
btn.ownerCt.ownerCt.close();
}
}
}, {
xtype : "button",
text : "取消",
listeners : {
"click" : function(btn) {
btn.ownerCt.ownerCt.close();
}
}
} ]
}
}); // 窗体
var window = Ext.create("Ext.window.Window", {
title : "学生成绩表",
width : 600,
height : 400,
items : myGrid,
layout : "fit",
tbar : {
xtype : "toolbar",
items : [ {
xtype : "button",
text : "新窗体新增",
listeners : {
"click" : function(btn) {
addPanel.getForm().reset();//新增前清空表格内容
addWindow.show();
}
}
}, {
xtype : "button",
text : "行编辑器新增",
listeners : {
"click" : function(btn) {
myGrid.getStore().insert(0, {});
var rowEdit = myGrid.plugins[0];
rowEdit.cancelEdit();
rowEdit.startEdit(0, 0);
}
}
}, {
xtype : "button",
text : "删除",
listeners : {
"click" : function(btn) {
var records = myGrid.getSelectionModel().getSelection();
myGrid.getStore().remove(records);
}
}
} ]
}
});
window.show();
});
</script> </head> <body>
添加。删除表格记录(行编辑器,适合改动字段少)
<br>
</body>
</html>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
extjs_04_grid(弹出窗口&行编辑器 CRUD数据)的更多相关文章
- C# GridView弹出窗口新增行 删除行
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" ...
- [转]js来弹出窗口的详细说明
1.警告对话框 <script> alert("警告文字") </script> 2.确认对话框 <script> confirm(" ...
- 在HTML网页中设置弹出窗口的办法
[1.最基本的弹出窗口代码] 其实代码非常简单: <SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.h ...
- JS弹出窗口代码大全(详细整理)
1.弹启一个全屏窗口 复制代码代码如下: <html> <body http://www.jb51.net','脚本之家','fullscreen');">; < ...
- 深入浅出ExtJS 第七章 弹出窗口
7.1 Ext.MessageBox 7.1 Ext.MessageBox //Ext.MessageBox为我们提供的alert/confirm/prompt等完全可以代替浏览器原生; 7.1.1 ...
- asp .NET弹出窗口 汇总(精华,麒麟创想)
asp .NET弹出窗口 汇总(精华,麒麟创想) 注://关闭,父窗口弹出对话框,子窗口直接关闭 this.Response.Write("<script language=javas ...
- EPUB弹出窗口式脚注
网上搜到一些国学典籍的EPUB版,虽有古人的注解,但正文和注解混排在一起,当我只想迅速读正文的时候比较碍眼.于是研究了一下 EPUB3 中有关脚注(footnote)的规格定义,写了一个 Python ...
- [置顶] html学习笔记,锚点,超链接,table布局,表头,h,sub,blockquote,ul,li,ol.dl,加入收藏,打印,弹出窗口
<a name="shouye"></a> <strong>strong加粗</strong> <br> 没有加粗 &l ...
- jQuery弹出窗口完整代码
jQuery弹出窗口完整代码 效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/1.htm 1 <!DOCTYPE html PUBLIC "- ...
随机推荐
- 【转】 随机梯度下降(Stochastic gradient descent)和 批量梯度下降(Batch gradient descent )的公式对比、实现对比
梯度下降(GD)是最小化风险函数.损失函数的一种常用方法,随机梯度下降和批量梯度下降是两种迭代求解思路,下面从公式和实现的角度对两者进行分析,如有哪个方面写的不对,希望网友纠正. 下面的h(x)是要拟 ...
- 大Q品牌故事_大Q官网_腾讯旗下买卖宝公司倾力打造
大Q品牌故事_大Q官网_腾讯旗下买卖宝公司倾力打造 走在大路上的改变者,有态度的互联网手机品牌
- CentOS下mysql最大连接数设置 1040 too many connection
当最大连接数比較小时,可能会出现"1040 too many connection"错误. 能够通过改动配置文件来改动最大连接数,但我连配置文件在哪都不知道,应该怎么办呢? 首先须 ...
- iOS 文件操作:沙盒(SandBox)、文件操作(FileManager)、程序包(NSBundle)
版权声明:本文为博主原创文章,转载请声明出处:http://blog.csdn.net/jinnchang 1.沙盒机制介绍 iOS 中的沙盒机制(SandBox)是一种安全体系.每个 iOS 应用程 ...
- ViewPager+View实现Tab
注:源码来自慕课网. 使用ViewPager+View实现Tab底部导航: 主要思想:顶部top.xml,中间ViewPager,底部线性布局Tab导航. top.xml具体实现: <?xml ...
- c/c++字符数组和字符串大揭秘
第一:写这篇文章源于我对'\0'和“\0”的探讨 当我对char a []="\0"; int size_a=sizeof(a); //结果为2 当时我很纳闷字符串不是以'\0'结 ...
- Struts+Tomcat搭建
Struts+Tomcat搭建 tomcat使用(服务器端开发): 如果要安装Tomcat需要进行的配置:tomcat安装在c: \Tomcat CATALINA_HOME变量值设为: H:\Prog ...
- BZOJ 1637: [Usaco2007 Mar]Balanced Lineup( sort + 前缀和 )
将 0 变为 -1 , 则只需找区间和为 0 , 即前缀和相同的最长区间 , 记录一下每个前缀和出现的最早和最晚的位置 , 比较一下就 OK 了 --------------------------- ...
- 使用jstl 截取字符串
时常碰见这样的 问题:获取数据库中的文本域的时候经常是在p标签中的,在页面显示的时候也是带着p标签,如何去除p标签呢 这里提供一个使用jstl的方式 1.首先导入jstl的函数标签库 <%@ t ...
- NOI2015 寿司晚宴
今年NOI确实是在下输了.最近想把当时不会做的题都写一下. 题意 从2到n(500)这些数字中,选若干分给A,若干分给B,满足不存在:A的某个数和B的某个数的GCD不等于1. 对于寿司晚宴这题,标准解 ...