Jump to content

The ultimate community for Ruby on Rails developers.


Photo

[WTA] Why only page one can be exported to .xls?

paging export xls csv checkbox

  • Please log in to reply
No replies to this topic

#1 kikiwisaka

kikiwisaka

    Passenger

  • Members
  • 3 posts
  • LocationBatam - Indonesia

Posted 17 July 2014 - 03:28 AM

Hello all,

 

I've got a problem when I select all or some select the checkbox on data list which want to be export to .xls file. The exported result only data on page one (note data on all page when I've choose select all).

#Action Controller 
def xls_cr_report
	 params[:start]=nil if params[:start]==''
     params[:end]=nil if params[:end]==''
	 params[:work_id_cont]=nil if params[:work_id_cont]==''
	 
     @results = {}
     if (params[:start]!=nil and params[:end]!=nil) then
       @results = Kaminari.paginate_array(ComplainReport.find_by_sql("SELECT request_date, ticket_number, work_id, dmz, pipe_type, repair_team, start_work, end_work, ticket_note
                FROM complain_reports
                where request_date BETWEEN '#{params[:start]}' AND '#{params[:end]}'")).page(params[:page]).per(15)
		
		elsif (params[:start]==nil and params[:end]==nil) and params[:work_id_cont]!=nil then
		@results = Kaminari.paginate_array(ComplainReport.find_by_sql("SELECT request_date, ticket_number, work_id, dmz, pipe_type, repair_team, start_work, end_work, ticket_note
		FROM complain_reports
		where work_id = '#{params[:work_id_cont]}'")).page(params[:page]).per(15)
		else			
          @results = nil
        end
		
        respond_to do |format|
	  format.html
	  format.json { render json: @results }
	  format.xls
	end
  end
#View of cr_report
<div class="navbar navbar-inner block-header">
	<div class="muted pull-left"><i class="icon-briefcase"></i>Complain Reports <%= params[:start] %> - <%= params[:end] %></div>
</div>

<div class="block-content collapse in">
<%= form_tag({:controller=>"/complain_reports", :action=>"cr_report"}, :class => 'form-horizontal', :method=>"get") do %>
	<div class="control-group">
		<label for="cari_pelanggan"><i class="icon-search"></i>Report Period</label>
		<%= text_field_tag :start, '', :class => 'datepicker', :style=>'width:100px;', :placeholder => "Start Date" %> -
		<%= text_field_tag :end, '', :class => 'datepicker', :style=>'width:100px;', :placeholder => "End Date" %>
		<%= text_field_tag :work_id_cont, '', :placeholder => "Work ID", :style=>'width:100px;'  %>
		    
		<%= submit_tag :Go, :class => 'btn btn-primary', :name => nil %>
		<% if (params[:start]!='' and params[:end]!='' and @results) then %>
		<%= link_to raw("<i class='icon-print'></i> Print"), {:action => 'print_cr_report', :start => params[:start], :end => params[:end]}, :onclick=>"javascript:window.open(this.href,'print_cr_report', 'height=600, width=800');return false;", :class => 'btn btn-primary' %> 
		<%= link_to 'Export XLS', url_for(:action => 'xls_cr_report', :format => 'xls', :start => params[:start], :end => params[:end], :work_id_cont => params[:work_id_cont]) , :class => 'btn btn-primary' %>
		<% end %>
	</div>
<% end %>
<% if (params[:start]!='' and params[:end]!='' and @results) then %>
<style>
	td.datesmall {font-size:11px; width:50px;}
	th.verticaltitle {width:10px; font-size:10px;}
</style>
<table class="table table-striped table-bordered table-condensed">
  <thead>
    <tr>
	  <th class="verticaltitle"><input type="checkbox" id="selectAll" value="selectAll"</th>
          <th class="verticaltitle">Request Date</th>
          <th class="verticaltitle">Ticket ID</th>
          <th class="verticaltitle">Work ID</th>
          <th class="verticaltitle">DMZ</th>
          <th class="verticaltitle">Pipe Type</th>
	  <th class="verticaltitle">Repair Team</th>
	  <th class="verticaltitle">Start Work</th>
	  <th class="verticaltitle">End Work</th>
	  <th class="verticaltitle">Note</th>
    </tr>
  </thead>
  <tbody>
	<% @results.each do |rs| %>
	<tr>
		<td><%= check_box("xls_cr_report", rs.id) %></td>
		<td><%= rs.request_date %></td>
		<td><%= rs.ticket_number %></td>
		<td><%= rs.work_id %></td>
		<td><%= rs.dmz %></td>
		<td><%= rs.pipe_type %></td>
		<td><%= rs.repair_team %></td>
		<td><%= rs.start_work %></td>
		<td><%= rs.end_work %></td>
		<td><%= rs.ticket_note %></td>
    </tr>
	<% end %>
  </tbody>
</table>


<%= paginate @results %>

<% else %>
(Harap masukan tanggal awal periode report dan tanggal akhir periode report secara lengkap.)
<% end %>
</div>
</div>

<script>
$('#selectAll').click(function() {
   if (this.checked) {
       $('input[type="checkbox"]').each(function() {
           this.checked = true;                        
       });
   } else {
      $('input[type="checkbox"]').each(function() {
           this.checked = false;                        
       });
   } 
});

$(document).ready(function(){
    $('.datepicker').datepicker({
        format: 'yyyy-mm-dd', autoclose: true, language: 'id', weekStart: 0, todayBtn: 'linked'
    });
});
</script>

Anyone can give me some suggestion to fix it?

Thanks and regards.







Also tagged with one or more of these keywords: paging, export, xls, csv, checkbox

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users