Skip to content

Commit

Permalink
Updrading to jqgrid v3.5 (bis2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Heukmes committed Aug 3, 2009
1 parent f325bb1 commit ed49e62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
15 changes: 4 additions & 11 deletions app/controllers/users_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ def pets
pets = [] pets = []
total_entries = 0 total_entries = 0
end end
respond_to do |format| if request.xhr?
# Fields order is important in the to_jqgrid_json method (in this case : [:id,:name]) render :json => pets.to_jqgrid_json([:id,:name], params[:page], params[:rows], total_entries) and return
# It must be the same as display order in your datagrid
format.json { render :json => pets.to_jqgrid_json([:id,:name], params[:page], params[:rows], total_entries) }
end end
end end


Expand Down Expand Up @@ -70,13 +68,8 @@ def index
paginate :page => params[:page], :per_page => params[:rows] paginate :page => params[:page], :per_page => params[:rows]
order_by "#{params[:sidx]} #{params[:sord]}" order_by "#{params[:sidx]} #{params[:sord]}"
end end

if request.xhr?
respond_to do |format| render :json => users.to_jqgrid_json([:id,:pseudo,:firstname,:lastname,:email,:role], params[:page], params[:rows], users.total_entries) and return
format.html
# Fields order is important in the to_jqgrid_json method (in this case : [:id,:name])
# It must be the same as display order in your datagrid
format.json { render :json => users.to_jqgrid_json([:id,:pseudo,:firstname,:lastname,:email,:role],
params[:page], params[:rows], users.total_entries) }
end end
end end


Expand Down
31 changes: 21 additions & 10 deletions app/views/users/index.html.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<br/> <br/>
<hr/> <hr/>
<br/> <br/>
<h1>2) Simple DataGrid with selection link/button</h1> <h1>2) Simple DataGrid with selection link/button + search disabled</h1>
<script type="text/javascript"> <script type="text/javascript">


function handleSelection(id) { function handleSelection(id) {
Expand All @@ -29,14 +29,14 @@
{ :field => "email", :label => "Email" }, { :field => "email", :label => "Email" },
{ :field => "role", :label => "Role" } { :field => "role", :label => "Role" }
], ],
{ :selection_handler => "handleSelection", :height => 300 } { :selection_handler => "handleSelection", :height => 300, :search => false }
) %> ) %>
<!-- The ID of this button is important, it must be jqgrid ID (players_2) + _select_button --> <!-- The ID of this button is important, it must be jqgrid ID (players_2) + _select_button -->
<a href="#" id="players_2_select_button">Get ID of selected row</a> <a href="#" id="players_2_select_button">Get ID of selected row</a>
<br/> <br/>
<hr/> <hr/>
<br/> <br/>
<h1>3) Simple DataGrid with direct selection</h1> <h1>3) Simple DataGrid with direct selection + autowidth</h1>
<%= jqgrid("Football Players", "players_3", "/users", <%= jqgrid("Football Players", "players_3", "/users",
[ [
{ :field => "id", :label => "ID", :width => 35, :resizable => false }, { :field => "id", :label => "ID", :width => 35, :resizable => false },
Expand All @@ -46,12 +46,12 @@
{ :field => "email", :label => "Email" }, { :field => "email", :label => "Email" },
{ :field => "role", :label => "Role" } { :field => "role", :label => "Role" }
], ],
{ :selection_handler => "handleSelection", :direct_selection => true } { :selection_handler => "handleSelection", :direct_selection => true, :autowidth => true }
) %> ) %>
<br/> <br/>
<hr/> <hr/>
<br/> <br/>
<h1>4) Simple DataGrid with multiple selections</h1> <h1>4) Simple DataGrid with multiple selections + row numbers</h1>
<%= jqgrid("Football Players", "players_4", "/users", <%= jqgrid("Football Players", "players_4", "/users",
[ [
{ :field => "id", :label => "ID", :width => 35, :resizable => false }, { :field => "id", :label => "ID", :width => 35, :resizable => false },
Expand All @@ -61,7 +61,7 @@
{ :field => "email", :label => "Email" }, { :field => "email", :label => "Email" },
{ :field => "role", :label => "Role" } { :field => "role", :label => "Role" }
], ],
{ :selection_handler => "handleSelection", :multi_selection => true } { :selection_handler => "handleSelection", :multi_selection => true, :rownumbers => true }
) %> ) %>
<!-- The ID of this button is important, it must be jqgrid ID (players_4) + _select_button --> <!-- The ID of this button is important, it must be jqgrid ID (players_4) + _select_button -->
<a href="#" id="players_4_select_button">Get IDs of selected rows</a> <a href="#" id="players_4_select_button">Get IDs of selected rows</a>
Expand Down Expand Up @@ -224,11 +224,11 @@ function pickDates(id) {
<hr/> <hr/>
<br/> <br/>
<script type="text/javascript"> <script type="text/javascript">
function handleSubSelection(id) { function handleSubSelection(id) {
alert('ID selected : ' + id); alert('ID selected : ' + id);
} }
</script> </script>
<h1>12) Subgrids with selection</h1> <h1>12) Subgrids with selection</h1>
<%= jqgrid("Football Players", "players_11", "/users", <%= jqgrid("Football Players", "players_11", "/users",
Expand All @@ -250,6 +250,17 @@ function pickDates(id) {
} }
) %> ) %>
<br/> <br/>
<hr/>
<br/> <br/>
<br/> <h1>13) Form Improvements</h1>
<br/> <%= jqgrid("Football Players", "players_13", "/users",
[
{ :field => "id", :label => "ID", :width => 35, :resizable => false },
{ :field => "pseudo", :label => "Pseudo", :editable => true, :formoptions => { :rowpos => 1, :elmprefix => "(*)&nbsp;&nbsp" }, :editoptions => { :size => 22 }, :editrules => { :required => true } },
{ :field => "firstname", :label => "Firstname", :editable => true, :formoptions => { :rowpos => 4, :label => "A label" }, :editoptions => { :size => 22 } },
{ :field => "lastname", :label => "Lastname", :editable => true, :formoptions => { :rowpos => 5 }, :editoptions => { :size => 22 } },
{ :field => "email", :label => "Email", :editable => true, :formoptions => { :rowpos => 3 }, :editoptions => { :size => 22 } },
{ :field => "role", :label => "Role", :editable => true, :stype => "select", :edittype => "select", :formoptions => { :rowpos => 2 }, :editoptions => { :value => [["admin","admin"], ["player", "player"], ["defender","defender"]], :size => 22 } }
],
{ :add => true, :edit => true, :inline_edit => true, :delete => true, :edit_url => "/users/post_data" }
) %>

0 comments on commit ed49e62

Please sign in to comment.