標籤:extjs_03_grid增加資料
<%@ 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});// 新增panelvar addPanel = Ext.create("Ext.form.Panel", {items : [ {xtype : "textfield",fieldLabel : "學號",name : "stuNo"}, {xtype : "textfield",fieldLabel : "姓名",name : "stuName"}, {xtype : "textfield",fieldLabel : "班級",name : "stuClass"}, {xtype : "numberfield",fieldLabel : "語文",name : "chScore"}, {xtype : "numberfield",fieldLabel : "數學",name : "maScore"}, {xtype : "numberfield",fieldLabel : "英語",name : "enScore"} ]});// 新增視窗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 stuNo = form.findField("stuNo").getValue();var stuName = form.findField("stuName").getValue();var stuClass = form.findField("stuClass").getValue();var chScore = form.findField("chScore").getValue();var maScore = form.findField("maScore").getValue();var enScore = form.findField("enScore").getValue();Ext.Msg.alert("新增的資料", "{" + stuNo + ":" + stuName + ":" + stuClass + ":" + chScore + ":"+ maScore + ":" + enScore + "}");}}}, {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();}}}}});window.show();});</script></head><body>顯示表格<br></body></html>