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(弹出窗口&amp;行编辑器 CRUD数据)的更多相关文章

  1. C# GridView弹出窗口新增行 删除行

    <%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" ...

  2. [转]js来弹出窗口的详细说明

    1.警告对话框 <script> alert("警告文字") </script> 2.确认对话框 <script> confirm(" ...

  3. 在HTML网页中设置弹出窗口的办法

    [1.最基本的弹出窗口代码] 其实代码非常简单: <SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.h ...

  4. JS弹出窗口代码大全(详细整理)

    1.弹启一个全屏窗口 复制代码代码如下: <html> <body http://www.jb51.net','脚本之家','fullscreen');">; < ...

  5. 深入浅出ExtJS 第七章 弹出窗口

    7.1 Ext.MessageBox 7.1 Ext.MessageBox //Ext.MessageBox为我们提供的alert/confirm/prompt等完全可以代替浏览器原生; 7.1.1 ...

  6. asp .NET弹出窗口 汇总(精华,麒麟创想)

    asp .NET弹出窗口 汇总(精华,麒麟创想) 注://关闭,父窗口弹出对话框,子窗口直接关闭 this.Response.Write("<script language=javas ...

  7. EPUB弹出窗口式脚注

    网上搜到一些国学典籍的EPUB版,虽有古人的注解,但正文和注解混排在一起,当我只想迅速读正文的时候比较碍眼.于是研究了一下 EPUB3 中有关脚注(footnote)的规格定义,写了一个 Python ...

  8. [置顶] html学习笔记,锚点,超链接,table布局,表头,h,sub,blockquote,ul,li,ol.dl,加入收藏,打印,弹出窗口

    <a name="shouye"></a> <strong>strong加粗</strong> <br> 没有加粗 &l ...

  9. jQuery弹出窗口完整代码

    jQuery弹出窗口完整代码 效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/1.htm 1 <!DOCTYPE html PUBLIC "- ...

随机推荐

  1. struts ModelDriven

    在表单提交的时候传值是这样,name=admin.username name=admin.password,然后在action中定义属性admin生成get和set 也可以实现ModelDriven这 ...

  2. Windows Phone 8初学者开发—第5部分:布局和事件基础

    原文 Windows Phone 8初学者开发—第5部分:布局和事件基础 原文地址: http://channel9.msdn.com/Series/Windows-Phone-8-Developme ...

  3. 轻松搞定Linux端口转发

    一 从一台机到另一台机端口转发 启用网卡转发功能 #echo 1 > /proc/sys/net/ipv4/ip_forward 举例:从192.168.0.132:21521(新端口)访问19 ...

  4. 删除 Windows Azure 网站上的标准服务器头

    编辑人员注释: 本文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 请求和响应中包含的 HTTP 头是Web 服务器和浏览器之间的 HTTP 通信过程的一部分.例 ...

  5. 关于异或(Xor)的一点笔记

    因为博弈论里,尤其实在求sg函数时,经常会用到异或运算,所以我就把网上搜到的一些相关知识和自己的一些理解记下来. 如果出现差错,还请指出,谢谢! 异或:可以简称Xor,可以用数学符号⊕表示,计算机就一 ...

  6. java学习之生产者和消费者案例

    package com.gh.thread; /** * 生产者和消费者案例 * wait和sleep的区别 * wait不让出监视器锁,sleep让出监视器的锁 * @author ganhang ...

  7. Javabyte[]数组和十六进制String之间的转换Util------包含案例和代码

    Java中byte用二进制表示占用8位,而我们知道16进制的每个字符需要用4位二进制位来表示(23 + 22 + 21 + 20 = 15),所以我们就可以把每个byte转换成两个相应的16进制字符, ...

  8. leetcode先刷_Search in Rotated Sorted Array II

    上一页下一页,找到相同的旋转阵列的问题.假设数组元素一再怎么办呢?会发生什么? 我给大家举一个极端的例子.如果是这样的阵列中的元件.1,1,2,1,1,1,1,我们想看看这个数组2,刚开始A[midd ...

  9. NSnotificationCenter 正确使用姿势, removeObject 探索

    最近在做平板的过程中,发现了一些很不规范的代码.偶然修复支付bug的时候,看到其他项目代码,使用通知的地方没有移除,我以为我这个模块的支付闪退是因为他通知没有移除的缘故.而在debug和看了具体的代码 ...

  10. 笔记之Cyclone IV 第一卷第一章FPGA 器件系列概述

    因为本人用的黑金四代开发板,中央芯片采用ALTERA的cycloneIV E,所以就此器件阅读altera官网资料,并做相应的笔记,以便于以后查阅 Cyclone IV 器件系列具有以下特性:■ 低成 ...