Skip to content

Commit

Permalink
Remove Client Side Pagination.
Browse files Browse the repository at this point in the history
  • Loading branch information
yelvert committed Feb 3, 2011
1 parent 57d1a69 commit 1e081cc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 109 deletions.
40 changes: 12 additions & 28 deletions app/coffeescripts/jTable.coffee
Expand Up @@ -8,7 +8,6 @@
perPage: 25
perPageOptions: [25,50,100]
fullPagination: true
serverSidePagination: true
ajaxInterval: 250
noItemsMsg: "No Records were found."
rowClass: ''
Expand Down Expand Up @@ -71,13 +70,8 @@
@previous_query = $.extend(true, {}, current_query)

updateItems = (data) =>
if @settings.serverSidePagination
@items_count = data.total_items
items = data.items
else
@items_count = data.length
items = data
@page = 1
@items_count = data.total_items
items = data.items
@items = []
for item in items
@items.push item
Expand Down Expand Up @@ -328,29 +322,19 @@
$(".jTable-pagination-button[data-jTable-pagination-page=#{@page}]", @container).addClass('jTable-pagination-current-page')

changePage = (new_page) =>
if @settings.serverSidePagination
if @initial_load
@page = new_page
updatePageInfo()
updatePagination()
else
if @stale_paging
@query.offset = ((new_page-1)*@settings.perPage)
@page = new_page
fetchItems()
else
@page = new_page
updatePageInfo()
updatePagination()
else
if @initial_load
@page = new_page
$('tr[data-jTable-row-index]',@table).hide()
i = (@page-1)*@settings.perPage
while (i < @page*@settings.perPage)
$("tr[data-jTable-row-index='#{i}']",@table).show()
i++
updatePageInfo()
updatePagination()
else
if @stale_paging
@query.offset = ((new_page-1)*@settings.perPage)
@page = new_page
fetchItems()
else
@page = new_page
updatePageInfo()
updatePagination()

insertItemAttributesIntoString = (item, str) =>
str = str.toString()
Expand Down
10 changes: 0 additions & 10 deletions app/controllers/widgets_controller.rb
Expand Up @@ -11,16 +11,6 @@ def index
end
end

def client_side
respond_to do |format|
format.html {}
format.json {
@widgets = Widget.jtable_query(params[:jTableQuery])
render :json => @widgets
}
end
end

# GET /widgets/1
# GET /widgets/1.xml
def show
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/application.html.erb
Expand Up @@ -16,8 +16,7 @@

<ul>
<li><%= link_to "ICD Codes", icd_codes_path %></li>
<li><%= link_to "Server Side Widgets", widgets_path %></li>
<li><%= link_to "Client Side Widgets", client_side_widgets_path %></li>
<li><%= link_to "Widgets", widgets_path %></li>
</ul>

<%= yield %>
Expand Down
27 changes: 0 additions & 27 deletions app/views/widgets/client_side.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/widgets/index.html.erb
@@ -1,10 +1,5 @@
<h1>Listing widgets</h1>

<p>
<%= link_to "Client Side", client_side_widgets_path %>
</p>

<h2>All Server Side</h2>
<div id="widgets1"></div>
<script type="text/javascript" charset="utf-8">
$("#widgets1").jTable({
Expand Down
7 changes: 3 additions & 4 deletions config/routes.rb
@@ -1,8 +1,7 @@
JTable::Application.routes.draw do
resources :icd_codes

resources :widgets do
get :client_side, :on => :collection
end

resources :widgets

root :to => "icd_codes#index"
end
46 changes: 13 additions & 33 deletions public/javascripts/jTable.js
@@ -1,4 +1,4 @@
/* DO NOT MODIFY. This file was compiled Thu, 03 Feb 2011 00:27:45 GMT from
/* DO NOT MODIFY. This file was compiled Thu, 03 Feb 2011 07:18:14 GMT from
* /Users/yelvert/projects/jtable/app/coffeescripts/jTable.coffee
*/

Expand All @@ -13,7 +13,6 @@ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments)
perPage: 25,
perPageOptions: [25, 50, 100],
fullPagination: true,
serverSidePagination: true,
ajaxInterval: 250,
noItemsMsg: "No Records were found.",
rowClass: '',
Expand Down Expand Up @@ -92,14 +91,8 @@ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments)
}, this);
updateItems = __bind(function(data) {
var item, items, _i, _len;
if (this.settings.serverSidePagination) {
this.items_count = data.total_items;
items = data.items;
} else {
this.items_count = data.length;
items = data;
this.page = 1;
}
this.items_count = data.total_items;
items = data.items;
this.items = [];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
Expand Down Expand Up @@ -435,33 +428,20 @@ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments)
return $(".jTable-pagination-button[data-jTable-pagination-page=" + this.page + "]", this.container).addClass('jTable-pagination-current-page');
}, this);
changePage = __bind(function(new_page) {
var i;
if (this.settings.serverSidePagination) {
if (this.initial_load) {
if (this.initial_load) {
this.page = new_page;
updatePageInfo();
return updatePagination();
} else {
if (this.stale_paging) {
this.query.offset = (new_page - 1) * this.settings.perPage;
this.page = new_page;
return fetchItems();
} else {
this.page = new_page;
updatePageInfo();
return updatePagination();
} else {
if (this.stale_paging) {
this.query.offset = (new_page - 1) * this.settings.perPage;
this.page = new_page;
return fetchItems();
} else {
this.page = new_page;
updatePageInfo();
return updatePagination();
}
}
} else {
this.page = new_page;
$('tr[data-jTable-row-index]', this.table).hide();
i = (this.page - 1) * this.settings.perPage;
while (i < this.page * this.settings.perPage) {
$("tr[data-jTable-row-index='" + i + "']", this.table).show();
i++;
}
updatePageInfo();
return updatePagination();
}
}, this);
insertItemAttributesIntoString = __bind(function(item, str) {
Expand Down

0 comments on commit 1e081cc

Please sign in to comment.