I’m back, and despite the fact that I haven’t posted in a bit I’ve been accomplishing quite a bit on the site …or maybe not. You see, I started keeping track of the hours I’ve been spending working on the site. Over the last 6 days I’ve put in 11 hours on the site. That’s a pretty good amount of time I’ve put in, actually, considering that my goal is to put in at least 8 hours (the equivalent of one work day) a week on the site.
On the (perhaps) not so good side, the majority of that time has been spent implementing pagination on the search results page. You would think this would be incredibly easy considering that CodeIgniter has a Pagination class. It shouldn’t take me approximately 8 hours, right? Well, apparently it does when you’re trying to use AJAX to handle your pagination. I was even perfectly willing to accept a complete hack for a solution, but alas, anything I tried to do to cobble together a fix for one issue only introduced another issue somewhere else.
Eventually jQuery came to my rescue. In the configuration for Pagination I set the base_url to ” (an empty string) so that the href on the pagination links would contain only the number for the search results. Then I set up jQuery to find all of the anchor links in my paging div, stop the normal link function, and call my function to load in the search results. The jQuery code came out like this:
$(document).ready(function(){
$("div.paging > a").click(function(e){
// stop normal link click
e.preventDefault();
$('div#search_results').load("/search/get_results/"+$(this).attr("href"));
});
});
This is still something of a hack as I’m basically creating fake href values for the anchor tags, but whatever, it works! I can come back later and fix it. At this point hacks are okay. Speed is much more valuable than perfectly elegant code as I want to find out if my idea is solid before investing oodles of time in it.
cool ^^
Thanks
Hello scott, I was hoping you could help me with my code similar to this one. I came up also with this idea and I was wondering how did you get the page numbers updated after clicking one of the numbered links?
Never mind scott I figured it out now. By the way nice post :)