tylzhuang
6 Apr 2007, 8:13 PM
I am from china, my english is pool.
I may use ext in my test apps.
I may offer my add and mod grid examples for all that need help !
edit-grid.js:
Ext.onReady(function(){
var myPageSize = 3;
function formatStatus(value){
return (value == 0)? '在线' : '离线';
};
// shorthand alias
var fm = Ext.form, Ed = Ext.grid.GridEditor;
// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store (created below)
var cm = new Ext.grid.ColumnModel([{
header: "帐号",
dataIndex: 'user_id',
width: 100
},{
header: "姓名",
dataIndex: 'user_name',
width: 100,
editor: new Ed(new fm.TextField({
allowBlank: false
}))},{
header: "状态",
dataIndex: 'status',
width: 100,
renderer: formatStatus,
editor: new Ed(new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
transform:'status',
lazyRender:true
}))
}]);
// by default columns are sortable
cm.defaultSortable = true;
// this could be inline, but we want to define the Plant record
// type so we can add records dynamically
var Plant = Ext.data.Record.create([
// the "name" below matches the tag name to read, except "availDate"
// which is mapped to the tag "availability"
{name: 'user_id', type: 'string'},
{name: 'user_name', type: 'string'},
{name: 'status'}
]);
// create the Data Store
var ds = new Ext.data.Store({
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.ScriptTagProxy({
url: myPath + '/testEditor.do?eventSubmit_doEdit=doEdit'
}),
// create reader that reads the Topic records
reader: new Ext.data.JsonReader({
root: 'users',
totalProperty: 'totalCount',
id: 'user_seq'
}, [
{name: 'user_id', mapping: 'user_id'},
{name: 'user_name', mapping: 'user_name'},
{name: 'status', mapping: 'status'}
]),
// turn on remote sorting
remoteSort: true
});
ds.setDefaultSort('user_seq', 'ASC');//排序用的列名和排序方式
// create the editor grid
var grid = new Ext.grid.EditorGrid('editor-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.CellSelectionModel(),
enableColLock:false
});
var layout = Ext.BorderLayout.create({
center: {
margins:{left:1,top:3,right:1,bottom:3},
panels: [new Ext.GridPanel(grid)]
}
}, 'grid-panel');
// render it
grid.render();
var gridFoot = grid.getView().getFooterPanel(true);
// add a paging toolbar to the grid's footer
var paging = new Ext.PagingToolbar(gridFoot, ds, {
pageSize: myPageSize,
displayInfo: true,
displayMsg: '总 {2} 条记录,当前显示 {0} - {1}',
emptyMsg: "没有记录"
});
// add the detailed view button
paging.add('-', {
pressed: true,
enableToggle:true,
text: 'submit modifiedData',
cls: '',
toggleHandler: doSubmit
});
// trigger the data store load
ds.load({params:{start:0, limit:myPageSize}});
//ds.load();
function doSubmit(){
var m = ds.modified.slice(0);
var jsonData = "[";
for(var i = 0, len = m.length; i < len; i++){
//alert(m[i].data["user_name"]);
var ss = JSON.stringify(m[i].data);
//alert(ss);
if(i==0)
jsonData = jsonData + ss;
else
jsonData = jsonData + "," + ss;
}
jsonData = jsonData + "]";
//alert(jsonData);
//组织json格式数据,然后提交后台
//alert(paging.cursor);
ds.modified = [];//将修改过的记录置为空,如果不清空,则修改过的数据会一直保留
ds.load({params:{start:paging.cursor, limit:myPageSize ,modifiedData:jsonData}});
}
Struts action :
// 从前台获得组织json格式数据进行传送
String modiData = request.getParameter("modifiedData");
if (modiData != null) {
modiData = Convertor.iso2utf(modiData);
System.out.println("-----modiData--1----" + modiData);
JSONArray jsonArr = null;
try {
jsonArr = new JSONArray(modiData);
for (int i = 0; i < jsonArr.length(); i++) {
String user_id = jsonArr.getJSONObject(i).getString(
"user_id");
String user_name = jsonArr.getJSONObject(i).getString(
"user_name");
String status = jsonArr.getJSONObject(i).getString(
"status");
// System.out.println(" bh == " + bh + " sm == " + sm);
String sql = "update system_users set user_name='"
+ user_name + "',status='" + status
+ "' where user_id='" + user_id + "'";
System.out.println(" update sql == " + sql );
int iii = BasePeer.executeStatement(sql);
System.out.println("update result == " + iii);
}
} catch (Exception pe) {
System.out.println("ParseException: " + pe.toString());
}
}
everone may mail to me , my email:tylzhuang@sohu.com
I may use ext in my test apps.
I may offer my add and mod grid examples for all that need help !
edit-grid.js:
Ext.onReady(function(){
var myPageSize = 3;
function formatStatus(value){
return (value == 0)? '在线' : '离线';
};
// shorthand alias
var fm = Ext.form, Ed = Ext.grid.GridEditor;
// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store (created below)
var cm = new Ext.grid.ColumnModel([{
header: "帐号",
dataIndex: 'user_id',
width: 100
},{
header: "姓名",
dataIndex: 'user_name',
width: 100,
editor: new Ed(new fm.TextField({
allowBlank: false
}))},{
header: "状态",
dataIndex: 'status',
width: 100,
renderer: formatStatus,
editor: new Ed(new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
transform:'status',
lazyRender:true
}))
}]);
// by default columns are sortable
cm.defaultSortable = true;
// this could be inline, but we want to define the Plant record
// type so we can add records dynamically
var Plant = Ext.data.Record.create([
// the "name" below matches the tag name to read, except "availDate"
// which is mapped to the tag "availability"
{name: 'user_id', type: 'string'},
{name: 'user_name', type: 'string'},
{name: 'status'}
]);
// create the Data Store
var ds = new Ext.data.Store({
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.ScriptTagProxy({
url: myPath + '/testEditor.do?eventSubmit_doEdit=doEdit'
}),
// create reader that reads the Topic records
reader: new Ext.data.JsonReader({
root: 'users',
totalProperty: 'totalCount',
id: 'user_seq'
}, [
{name: 'user_id', mapping: 'user_id'},
{name: 'user_name', mapping: 'user_name'},
{name: 'status', mapping: 'status'}
]),
// turn on remote sorting
remoteSort: true
});
ds.setDefaultSort('user_seq', 'ASC');//排序用的列名和排序方式
// create the editor grid
var grid = new Ext.grid.EditorGrid('editor-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.CellSelectionModel(),
enableColLock:false
});
var layout = Ext.BorderLayout.create({
center: {
margins:{left:1,top:3,right:1,bottom:3},
panels: [new Ext.GridPanel(grid)]
}
}, 'grid-panel');
// render it
grid.render();
var gridFoot = grid.getView().getFooterPanel(true);
// add a paging toolbar to the grid's footer
var paging = new Ext.PagingToolbar(gridFoot, ds, {
pageSize: myPageSize,
displayInfo: true,
displayMsg: '总 {2} 条记录,当前显示 {0} - {1}',
emptyMsg: "没有记录"
});
// add the detailed view button
paging.add('-', {
pressed: true,
enableToggle:true,
text: 'submit modifiedData',
cls: '',
toggleHandler: doSubmit
});
// trigger the data store load
ds.load({params:{start:0, limit:myPageSize}});
//ds.load();
function doSubmit(){
var m = ds.modified.slice(0);
var jsonData = "[";
for(var i = 0, len = m.length; i < len; i++){
//alert(m[i].data["user_name"]);
var ss = JSON.stringify(m[i].data);
//alert(ss);
if(i==0)
jsonData = jsonData + ss;
else
jsonData = jsonData + "," + ss;
}
jsonData = jsonData + "]";
//alert(jsonData);
//组织json格式数据,然后提交后台
//alert(paging.cursor);
ds.modified = [];//将修改过的记录置为空,如果不清空,则修改过的数据会一直保留
ds.load({params:{start:paging.cursor, limit:myPageSize ,modifiedData:jsonData}});
}
Struts action :
// 从前台获得组织json格式数据进行传送
String modiData = request.getParameter("modifiedData");
if (modiData != null) {
modiData = Convertor.iso2utf(modiData);
System.out.println("-----modiData--1----" + modiData);
JSONArray jsonArr = null;
try {
jsonArr = new JSONArray(modiData);
for (int i = 0; i < jsonArr.length(); i++) {
String user_id = jsonArr.getJSONObject(i).getString(
"user_id");
String user_name = jsonArr.getJSONObject(i).getString(
"user_name");
String status = jsonArr.getJSONObject(i).getString(
"status");
// System.out.println(" bh == " + bh + " sm == " + sm);
String sql = "update system_users set user_name='"
+ user_name + "',status='" + status
+ "' where user_id='" + user_id + "'";
System.out.println(" update sql == " + sql );
int iii = BasePeer.executeStatement(sql);
System.out.println("update result == " + iii);
}
} catch (Exception pe) {
System.out.println("ParseException: " + pe.toString());
}
}
everone may mail to me , my email:tylzhuang@sohu.com