I'm working with ruby 1.8.7 and rails 2.3.5.
I use will_paginate to display the result of a database request.
and i well display 20 results per page and i have lets say 15 pages to display.
Now i need to print the whole list, i found out a printing method adding a link into my view file erb <%=link_to_function("Print this Page", "javascript:print()")%>
But it only print the 20 results available on the screen. Is there a method to print the 300 results in one clic
Thanks for all advises and ideas
The print link should send to a non paginated print page with the 300 results and then print from here, you try to print from a view which only has access to the paginated object.
Related
I am trying to scrape this page using Nokogiri to get all the elements with class name of "teaser".
If I check the page with jQuery, I can see there are 25 elements:
$(".teaser").length => 25
However, when using Nokogiri, I only get the first teaser:
teasers = doc.css('.teaser')
teasers.count => 1
Where am I going wrong? How do I get all the teasers?
That document appears to have a load of null bytes in it for some reason, and this is causing Nokogiri/LibXML to assume the document has finished part way through.
You should be able to fix it by preprocessing the contents to remove the nulls. If page contains the text of the webpage:
page.gsub! /\x00/, ''
Then use Nokogiri on page as before.
I have a specific requirement which allows the user to download records for an entire month. This can include a range from 15,000 to 20,000 records. I have an optimized query, but the issue is in the html rendering. Basically, it goes through each record and formats it by time, date, speed, etc. The problem is right now it is taking over 6 minutes to actually render the table with the content on it on an html print window. If I cannot optimize the query or rendering anymore, what other options do I have? (Note there is no point saving the page as a cache because such large quantity of records will only ever be downloaded once per month)
#query
#reports = unit.reports.where("reports.time > ? and reports.time < ?",range.begin, range.end)
#reports = #reports.includes(:alerts)
#view rendering:
- #reports.each do |r|
%tr
%td.num_col #{Report.index_of(#reports, r)}
- if #history_date
%td.time_col #{time_format(r.time)}
- else
%td.time_col #{datetime_format(r.time)}
- if #unit.unit_type.name == "MarineTrac"
%td.latitude_col #{r.latitude.to_s}
%td.longitude_col #{r.longitude.to_s}
%td.address_col{:title => r.address_formatted} #{r.address_formatted(:street => false)}
- else
%td.street_col{:title => r.street} #{r.street}
%td.speed_col #{speed_formatted(r)}
%td.distance_col #{r.distance}
- if r.alerts.any?
%td.alert_col
%ul{:style => "margin: 0px; padding: 0px; list-style-type: none;"}
- r.alerts.each do |alert|
%li
%span{:class => "#{alert.class_for_severity}"}= alert_full_str(alert)
- else
%td.alerts_col{:class => "severity_none"} None
%td.signal_col #{r.signal_formatted}
%td.fix_col #{r.gps_valid_str}
I would recommend extracting the report generation into a background process.
Basically, use something like Sidekiq to enqueue the report to be generated when the user requests it. You can then return immediately and tell them something like "Your report is now being generated. You will receive an email when it completes."
Your Sidekiq worker would do all the work, and simply shoot off an email to the user when it is done.
Use pagination to split up the results into manageable chunks, I prefer Kaminari.
I suspect that you are going to need all the results on a single page. To handle this, you can use pagination along with jQuery infinite scroll to load more results as the user scrolls down the page. Not only will this speed up initial page load, but it will put less stress on the server if the user is only looking for the first batch of results, all while keeping everything listed on one page.
Even if loading on scroll isn't an option, you could still use ajax to load each pagination 'page' (say 2,000 results per page?) a section at a time. Or depending on how beefy your server is and how fast you need the results, you could spawn all the required ajax page loads asynchronously
Export it as a CSV they can download.
If you need it for viewing, you can use pagination so you will render only part of the results each time - For example use the will_paginate gem
If you need to display all...try to make it a PDF, I think Prawn gem is a good one for that
Good luck
u should have a look at http://jiren.github.io/StreamTable.js/stream.html. It fetches 'n' records initially, renders the page while simultaneously it keep loading the remaining data from server so that u don't have to wait for the entire data to be loaded for rendering. It also has pagination support and also displays the amount of data currently loaded.
I want to achieve print functionality such that user can print out the web form and use it as paper form for the same purpose. Of course I do not need all the web page header and footer to be printed, just content of a div which take most of the page. I did play around with media print css and menage print result to look almost as original page. But the I tried to print it in another browser(Chrome) and it is all messed. (before I tried Mozilla).
For the web form I user css framework Twitter Bootstrap and I had to override its css (in print media) for almost each element individually to get some normal look in the print result.
My question is is there some way (framework/plugin) to print just what you see on the page, maybe as an image or something?
Any other suggestions are welcome.
Thanks.
If you are familiar with PHP you can try the PHP class files of TCPDF or those of FPDF.
Or there is also dompdf which renders HTML to PDF, but this will include more than just the information of one div.
And for further info here is a post on Stack where users are discussing which they think is best.
I'm building my own forum software, and in the thread display I am paginating replies. It works well, except that I need to exclude the first post from pagination since it is rendered separately and differently.
I have tried a number of approaches, including:
Putting "offset: 1" in the controller's paginate command, which works properly but produces the same post list for each page
The first approach listed at get will_paginate to define a custom offset on the first page, which does not work in my case (I am paginating #discussion.posts instead of just #posts).
What's the best way to solve this issue?
A simple solution is just to check that if you are on Page 1
params[:page] == 1
And if so, then only render the collection of replies, except for the first.
#replies[1..-1].each do (reply)
..
I'm trying to use will paginate with ajax, but I don't show the will_paginate buttons... instead I use a see more button, that makes an Ajax request and append the results to the page.
what I'm trying to do is disable this see more button if I hit the last page of records!!
Any idea how to know that the current page is the last page??
#collection.total_pages == #collection.current_page
Accessing the #collection.total_pages method will give you the total number of pages currently being returned. You can use this to evaluate against your active page using the #collection.current_page method. This is still applicable if you're reloading your collection on each expansion.
The implementation will be to use the AJAX call to replace the HTML content if this evaluation is true.
You can use next_page condition
#collection.next_page.present?