Need help with Ajax Pagination |
[eluser]Wonder Woman[/eluser]
Hi, Basically I have an ajax search but I'd like to incorporate pagination into the results, at the moment they are returned in a list inside a div. My controller looks like this: Code: function index() My model looks like this: Code: function getSearchResults($location) My view looks like this: Code: <div id="property_description"> With the ajax file looking like this: Code: window.onload = function () { If you could advise me that would be great. I am new to codeigniter. Thanks.
[eluser]WanWizard[/eluser]
Advise you on what exactly? You haven't asked a single question (if you forget the one in the subject).
[eluser]Wonder Woman[/eluser]
I did, I said I'd like to incorporate pagination into the results, ok so maybe I didn't put it as a question exactly but I was just wondering how I could implement pagination in to my results.
[eluser]Gyzm[/eluser]
Hey fpp, The Pagination class by default isn't setup to work via AJAX. As of yesterday I've modified it to be able to do so. The problem is in the create_links() function because it only creates regular links. There is no ability to put the Code: '#' Code: 'onclick="func();"' Please note that you'll probably want to extend the Pagination class rather than directly modify it so that, when updating codeigniter, you won't undo this code. Unfortunately I haven't done that yet; I just went ahead and modified the original so that's what I'm about to give you. Maybe just rename the original and put this one in it's place for now. I'll extend it later. No time right now. Note that there is one new Class Variable call 'use_ajax' set to false by default. when set to true: Code: $config['use_ajax'] = true; Code: <a href="#" nclick="ajax_pagination();">link number</a> So now all of your page links will be set to call a javascript function called ajax_pagination() and the argument passed will obviously be the page number. So now in your in your ajax_pagination() function you'll have your AJAX request with your URL set to http://yoursite.com/controller/function/page_number so: Code: url: 'http://' + location.href + '/controller/function/' + n Code: function ajax_pagination(n){ Lastly, you'll have to remember to send your links over through javascript. so: Code: $data['plinks'] = $this->pagination->create_links(); There is quite a bit to this so I hope that you're very familiar with a particular JS library and especially AJAX. File is attached. Cheers. |
Welcome Guest, Not a member yet? Register Sign In |