Permalink
Browse files

查询分页 & 几个ext扩展

  • Loading branch information...
1 parent fb5f751 commit 879ec010fa30e8d22f6a2063aa9057af29f1375f @xEasy xEasy committed Mar 23, 2012
@@ -2,8 +2,12 @@ class HomesController < ApplicationController
def index
end
- def get_classes_students
- render_json Classes.find(params[:c_id]).students.number_like(params[:query]).order("#{params[:sort]} #{params[:dir]}").collect &fields_provider
+ def get_students
+ code = "Student.number_like(params[:query])"
+ result = eval( params[:c_id] ? code + ".classes_id_equals(params[:c_id])" : code)
+ total = result.count
+ result = result.order("#{params[:sort]} #{params[:dir]}").limit((params[:limit] || 25).to_i).offset(params[:start].to_i || 0).collect &fields_provider
+ render :json => { :root => result, :total => total }
end
def get_classes
@@ -26,7 +30,10 @@ def comment_type_tree_nodes
end
def commets_by_type
- render_json CommentType.find(params[:ct_id]).comments.content_like(params[:query]).collect &fields_provider
+ result = CommentType.find(params[:ct_id]).comments.content_like(params[:query])
+ total = result.count
+ result = result.order("#{params[:sort]} #{params[:dir]}").limit((params[:limit] || 15)).offset(params[:start].to_i || 0).collect &fields_provider
+ render :json => { :root => result, :total => total }
end
end
@@ -1,5 +1,10 @@
-<%= javascript_include_tag '/javascripts/PF/pages/comment_student.js' %>
+<style type="text/css" media="screen">
+ .x-grid3-cell-inner, .x-grid3-hd-inner {
+ white-space: pre-wrap;
+ }
+</style>
+<%= javascript_include_tag '/javascripts/PF/pages/comment_student.js' %>
<script language="javascript" type="text/javascript">
Ext.onReady(function() {
Pf.classes.commentStudent = new Pf.classes.commentStudent.MainPanel();
@@ -6,8 +6,10 @@
<%= javascript_include_tag 'Extjs/ext-all-debug.js' %>
<%= javascript_include_tag 'Extjs/ext-lang-zh_CN.js' %>
- <%= javascript_include_tag 'Extjs/ux/SearchField.js' %>
+ <%= javascript_include_tag 'PF/widgets/SearchField.js' %>
<%= javascript_include_tag 'Extjs/ux/FileUploadField.js' %>
+ <%= javascript_include_tag 'PF/widgets/GroupSummary.js' %>
+ <%= javascript_include_tag 'PF/widgets/SlidingPager.js' %>
<%= javascript_include_tag 'PF/public/init.js' %>
<%= javascript_include_tag 'PF/util/util.js' %>
@@ -16,6 +18,7 @@
<%= stylesheet_link_tag '/javascripts/Extjs/resources/css/ext-all.css' %>
<%= stylesheet_link_tag '/javascripts/Extjs/resources/css/xtheme-gray.css' %>
+ <%= stylesheet_link_tag 'GroupSummary.css' %>
<%= stylesheet_link_tag 'menu-style.css' %>
<%= stylesheet_link_tag 'fileuploadfield.css' %>
<%= stylesheet_link_tag 'button_icon.css' %>
View
@@ -3,9 +3,9 @@
collection do
get "index"
get "get_classes"
- get 'get_classes_students'
+ get 'get_students'
get 'student_detail'
- get 'student_score'
+ post 'student_score'
get 'comment_student'
post 'comment_type_tree_nodes'
get 'commets_by_type'
@@ -139,7 +139,9 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
emptyText : '请选择学生',
editable : false,
onTrigger2Click : function() {
- if (currentClasses != undefined) { scope.studentGrid.getStore().reload(); };
+ //if (currentClasses != undefined) {
+ scope.studentGrid.getStore().load();
+ //};
scope.studentWin.show();
}
});
@@ -177,10 +179,10 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
name: 'sex',
readOnly: true
},{
- fieldLabel: '评级',
- name: 'grade',
- readOnly: true
- }, {
+ // fieldLabel: '评级',
+ // name: 'grade',
+ // readOnly: true
+ //}, {
fieldLabel: '备注',
name: 'remark',
readOnly: true
@@ -214,6 +216,7 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
height : 230,
collapsible: true,
loadMask : true,
+ frame : true,
//collapseMode: 'mini',
store: store,
cm : cm,
@@ -229,7 +232,7 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
var scope = this;
var store = new Pf.util.FieldsJsonStore({
root : 'root',
- url : '/homes/get_classes_students.json',
+ url : '/homes/get_students.json',
fields : [
"id",
'name',
@@ -241,9 +244,10 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
'classes/name',
'comment',
'image/url',
- 'grade',
+ //'grade',
]
});
+ store.load();
var cm = new Ext.grid.ColumnModel({
columns: [
@@ -299,6 +303,7 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
'学号查询: ', ' ', new Ext.ux.form.SearchField({ store: store, width: 220 })
]
}),
+ bbar: new Pf.util.Bbar({ store : store }),
sm : new Ext.grid.RowSelectionModel({ }),
listeners: {
celldblclick : function(grid,rowIndex,columnIndex) {
@@ -32,7 +32,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
var scope = this;
var store = new Pf.util.FieldsJsonStore({
root : 'root',
- url : '/homes/get_classes_students.json',
+ url : '/homes/get_students.json',
fields : [
"id",
'name',
@@ -45,8 +45,9 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
'comment',
'image/url',
'grade'
- ]
+ ]
});
+ store.load();
var cm = new Ext.grid.ColumnModel({
columns: [
@@ -74,7 +75,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
var store = Ext.getCmp("student-grid").getStore();
store.removeAll();
store.setBaseParam("c_id", record.get("id"));
- store.load();
+ store.reload();
}
}
});
@@ -86,7 +87,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
border: false,
containerScroll: true,
loadMask : true,
- width: 200,
+ width: 250,
region: 'west',
split: true,
title : "学生列表",
@@ -97,6 +98,11 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
labelWidth : 1,
items : ['班级:',classCombox, '学号查询:',new Ext.ux.form.SearchField({ emptyText : '请输入学号' ,store: store, width: 180 }) ]
}),
+ bbar: new Ext.PagingToolbar({
+ pageSize: 25,
+ store: store,
+ plugins: new Ext.ux.SlidingPager()
+ }),
sm : new Ext.grid.RowSelectionModel({
listeners : {
rowselect : function (model, row, record) {
@@ -126,25 +132,57 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
});
var cm = new Ext.grid.ColumnModel({
columns: [
- { header: '科目' , dataIndex: 'course/name', width : 50 },
{ header: '学期' , dataIndex: 'grade',width : 50 },
- { header: '成绩' , dataIndex: 'score', width : 50 },
+ { header: '科目' , dataIndex: 'course/name', width : 50,
+ summaryType: 'count',
+ summaryRenderer: function(v, params, data) { return ((v === 0 || v > 1) ? '(' + v + ' 科目)' : '(1 科目)'); }
+ },
+ { header: '成绩' , dataIndex: 'score', width : 50,
+ summaryType: 'sum',
+ summaryRenderer: function(v, params, data) { return "总分: " + ( v ); }
+ },
{ header: '成绩评级' , dataIndex: 'score_type', width : 50 },
{ header: '备注' , dataIndex: 'remark' },
],
defaults: { menuDisabled : true, sortable : true }
});
+
+ var reader = new Ext.data.JsonReader({
+ root : 'root',
+ fields : ['course/name','grade','score','remark','score_type']
+ });
+
+ // utilize custom extension for Group Summary
+ var summary = new Ext.ux.grid.GroupSummary();
+ var ds = new Ext.data.GroupingStore({
+ reader: reader,
+ url : '/homes/student_score.json',
+ groupField: 'grade'
+ });
+ ds.on('beforeload', function(st, options) {
+ st.setBaseParam('fields[]',store.fields.keys);
+ });
+
var grid = new Ext.grid.EditorGridPanel({
id : 'score-grid',
- store: store,
- loadMask :true,
+ title : "学生成绩",
+ store: ds,
cm : cm,
+ loadMask :true,
height : 200,
- sm : new Ext.grid.RowSelectionModel({}),
- title : "学生成绩",
+ frame : true,
+ enableColumnMove: false,
+ plugins: summary,
stripeRows: true,
viewConfig: { forceFit: true },
+ view: new Ext.grid.GroupingView({
+ forceFit: true,
+ showGroupName: false,
+ enableNoGroups: false,
+ enableGroupingMenu: false,
+ }),
});
+
var form = new Ext.FormPanel({
region : 'center',
frame : true,
Oops, something went wrong.

0 comments on commit 879ec01

Please sign in to comment.