Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.


I don't know how to create two sets of pagination links one view.

Background Information

I have a situation where I have parent / child tables that I have to display on the same view - perhaps in two different sections. Each section needs its own set of pagination links. The contents (and therefore, pagination links) in section 2 will change depending on what is selected in the parent section / section 1.

The parent is what I call "subcategories" and the child table is "products". SO when the user comes to the first page, all categories are shown. But once they select a specific category, I want to take them to this view that I'm discussing which will show any subcategories... and any products.

Possible Solution

I'm thinking that I need the following methods in my controller:

public function getsubcategories($categoryID)
    1.  find data yu need to display
    2.  set up pagination object
    3.  use add_js method to add ajax call to a method "get_products_in_category" 
        Ajax method to be invoked on document.ready and will return product data.
    4.  load view. 

public function get_products_in_cateogry($categoryID)
    1. look up products in category
    2.  build html to display products. 
    3.  return string with all html to display product information
    ??? can i create another pagination object here???

If you have any suggestions on what's wrong with my idea / how I can accomplish this, I'd really appreciate it

Thank you.

Edit 1

While waiting for a response, i went ahead and tried a little test... and it doesn't seem to be working. I still have the issue where the pagination links displayed in section 2 actually manipulates the data in section 1. I'm going to move post this question in stackoverflow. Thank you.

share|improve this question

closed as off-topic by MichaelT, GlenH7, Dan Pichelman, gnat, user61852 Feb 8 at 22:18

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

I'm voting to close this question as off-topic because an implementation or debugging issue that was moved to stack overflow (link) and is now more complete there... And is too old to migrate. –  MichaelT Feb 8 at 14:15

1 Answer 1

The two methods are correct but if you want to dinamically change the content of subcategories either you reload twice the page or you use ajax.

Without ajax you need to reload the page twice 1 for the selection of the parent category and 2 for the selection of the child category. The server has to know which was the parent category to return the set of subcategories. You can use Session to hold the information between reload 1 and 2 or just POST or GET, it depends on the way you design it.

With ajax you can avoid the reload because the javascript embedded in the page will take care to contact the server and fetch the results.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.