I can almost always find an answer searching stack overflow, but after many hours, I have come up blank. I am sure that I am doing something that should be easy, but complicating it for myself.
I have an "orders" index view with an AJAX search, sort and pagination. It's all set up based on this screen cast. Works fine.
However, I would like my users to be able to click a link to another page, which will be set up to print the results of the search, without the navigation, pagination, etc.
It seems the best way to do this is to have the new view perform the same search as was already performed on the index page.
I have created another route, action and view called print_list that is basically the same as the index page, but without the pagination, etc. Not very DRY, but for the purposes of this mockup, it's acceptable.
The question is how do I pass the AJAX search parameters to the other view? Basically, I need to pass the params into the link_to helper.
So for example:
<%=link_to "Print List", print_list_orders_path(:cat =>"name ", :search => "er", :range => "Forever") %>
renders:
Print List
...and that works fine, and passes those parameters. What I need is a way to be dynamically updating those params as the AJAX calls are made, and the Index page is updated. I could write a jQuery bit using:
$('.myLink').attr('href','/orders/print_list?cat=name+&range=Forever&search=er">');
and call it everytime the AJAX updates.(of course I would have to add the CSS class for that, obviously) However, that does not seem like the best way to do this, what with the hard coded path and all. Is there a more Railsy way?
I was also thinking that later in my development process, I wouldn't mind being able to save searches, so a method that could also be used to save the search for reuse later gets extra points.
Thanks for reading!
In case anyone ever has this problem - the solution is to use the rails session method, and store the search in the session.
Related
Trying to think of a good solution to this issue, I am trying to create a Form which would exist on multiple pages. At one point if you press an option on one of the buttons on page 1, it will bring you to page 2 where you select something, and then go back to page 1. The issue I am having is writing the code so that it will rember what was currently on page 1, and can pass the information from page 2 to page 1.
I am assuming I am going to have to use some sort of state management system to pull this off, but honestly have no clue. RIght now all I use is react native flux for navigation for page to page.. and thought about just passing everything as props.. but that seems clunky
Any help would be awesome!
Well, if your form is simple and you do need to have multiple screens, I see no reason not to use the props injected by react-native-router-flux. But if you are looking for something that can scale a bit better, why not try to put your form data in a temporal object inside your state manager. For the sake of the example, let's say redux. Create a reducer that stores an object with all the form data, and bind your different screens so that they can access it. Then, through actions, update the values when the user inputs something. There might be a few tricky edge cases, such as clearing all data when the form is submitted, what happens if the user cancels the action, etc... Sure, it looks a bit cumbersome to handle data in such a way, but I think it could be a nice solution.
I'm writing an asp.net website that has a search. Depending on the filter that they apply, the results will be different (Look and Data displayed). Are partial views the best way to go about this? I don't want the page to have to refresh every time they apply a new filter.
Yes, partial view is best approach for this, use ajax call to load partial view.
Please refer for more details : https://stackoverflow.com/a/38968860/6606630
Perhaps you are reffering to Ajax tech?
Check this link: http://www.asp.net/ajax
I've tried doing some research on the various jquery history plugins, but I can't find any examples for my situation, so I'm starting to think maybe what I'm trying to do is not possible.
We have a very complicated search page that updates with ajax. Users search using a ton of options, and they get back a list of results which they can sort, page etc. Then if they click on one of the results, it navigates them to another page to view the details. However, if they click Back they do not return back to how the page appeared after all the ajax and javascript updates. They see the search page with none of their results.
I was hoping that I could pull of something with adding a hash before they navigated away, or using one of the jquery history plugins to achieve something similar, so that when they clicked Back, it wouldn't RELOAD the search page, but would just show them their cached version (how it last looked when they clicked on one of the results).
From what I've seen, it looks like most of the examples I've found for ajax and back buttons use a hash value that tells the page how to arrange itself, even allowing for bookmarking the page that includes the hash. I think for me that would mean that I'd basically have to serialize everything in the search page into a hash value, which doesn't seem practical unless I am totally misunderstanding how it works.
Does anyone out there know if this possible?
There are at least 2 ways to do what you want:
"Classic" - store all user search options in cookie or in session, like "last search". So, when user navigates to search page during session, you can read cookie / session and show last search results with that options.
"Modern" way - use HTML5 history API - on each search form a search options object and push it in via history.pushState - when user navigate to other page and then presses "back", browser will use this state to perform a search.
If it's that complex, better you develop your own solution without any plugin. Just use location.hash to get and set hash value and store all form input elements and their values after hash like a querystring input1=a&input2=b
On every form submit update hash querystring
If user navigates back in history read hash value parse it and update your form fields and submit to get search results automatically.
you can check out SammyJS this is the plugin I used for ajax history. Hope it helps
I have a simple rails app with a model Task, which has 10 rows. It does not matter what's inside this table. On the index page I can see all 10 elements and I need to arrange them in proper sequence, when I did this, I should see a message "Done".
If I understand correctly this should be implemented in javascript, because page should not be reloaded, right?
I want to be able to rearrange the elements via drag and drop.
How I can realize that function?
I would start with here -> http://jqueryui.com/demos/sortable/
You can sort and its quite simple as there great examples on the site how to do this and hook into events.
What is the best way of doing a pagination? I would also need to save the current page, so that when I click a link it would save the page I was on. So if I'm on page 2 of the pagination and click one link and then get back to pagination page it would remember that I was on page 2.
I get the results/data from Json request where I have offset and limit possibility.
$.getJSON(base_url+'/ajax/get_news/4/!OFFSET!/!LIMIT!/true', func...
Where !LIMIT! is how many results it shows and !OFFSET! is, well offset :D When I click a link, it makes that request, it goes throught the results and appends the result into page.
What is best way to save the page, cookies? Should I get all the results and then do the pagination somehow or do new request when user change page?
Some tutorial or "hands on" example would be awesome. Normal instructions/guides are difficult to undestand since my first language isn't english.
It appears you have two questions:
1) How to save page state (what page you are on): If the application must continue to use an ajax, then you should look at storing the state in the url as discribed here:
http://ajaxpatterns.org/Unique_URLs
2) Regarding where to do the pagination, I think it would depend on the size of the data to paginate. If it is small and you are not worried about the data changing on between paging, do it all in javascript. Otherwise, do it server-side.
Okey I should use the !OFFSET! and !LIMIT! to do the pagination. I just need change those numbers with pagination links (1 2 3 4 pages etc) to get the pagination to work I believe. But I dont know where to start :/