PDA

View Full Version : Grid Pagination with mvc framework



dotsimple
6 May 2009, 4:20 AM
Hi...!

i don't know if this is possible, and I have searched but could not find what I am looking for. Perhaps a kind soul would direct me to where I should be reading for my trouble.

I have created a grid with pagination. I am trying this CodeIgniter framework and I like the URL parameters that follow the MVC rule! I mean I am trying to display data in a pagination form inside a grid and I am referencing the php function that returns a set of data in a certain page as follows:

www.myweb.com/customers/list/10/3 (where 10 is the page size and 3 is the number of the page to be displayed).

Now when I use the baseParams I take it that it sends the request as :
www.myweb.com/customers/list/?pagesize=10&pagenumber=3 When it does that my script no longer works. I don't really want to use the querystring format but rather the clean URL format such as the /10/3

How can i do this with the grid data.stiore baseParams? Can this be done? Is there another avenue I should follow?

Thank you kindly in advance...

And have a stunning day!

Condor
6 May 2009, 5:24 AM
You can modify both the params and the url in the beforeload event of the proxy.

dotsimple
6 May 2009, 5:38 AM
hi Condor - thank you for the quick reply! If I am to understand correctly I should look into the beforeload event and build somehow the requested url and then send it through to the server? I mean construct a URL string from the baseParams details? Or am I somehow loosing myself into this whole thing?? hehehehehe

Condor
6 May 2009, 5:44 AM
Something like:

proxy: new Ext.data.HttpProxy({
url: 'http://www.myweb.com/customers/list/',
listeners: {
beforeload: function(proxy, params){
var pageSize = params.limit;
var currentPage = Math.floor(params.start / pageSize);
proxy.conn.url = 'http://www.myweb.com/customers/list/' + pageSize + '/' + currentPage;
delete params.start;
delete params.limit;
}
}
})

dotsimple
6 May 2009, 5:46 AM
Oh man - you are a really amazing person - thank you! thank you!

t00bs
10 Apr 2010, 4:59 AM
I just spent most of the day working out how to achieve the same thing with mod_rewrite and then I came across Condor's solution. May as well post it as another option. It may be useful for moving existing client code to a MVC backend. Here's the .htaccess file I use for CodeIgniter serving to a paging grid.


RewriteEngine On
RewriteBase /myapp

#secure system folder
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#secure app folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#allow other files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

#Check for the start parameter
RewriteCond %{QUERY_STRING} ^.*start=([0-9]+)&?.*$
RewriteRule ^(.*)$ $1/%1 [DPI]

#Check for the limit parameter
RewriteCond %{QUERY_STRING} ^.*limit=([0-9]+)&?.*$
RewriteRule ^(.*)$ $1/%1 [DPI]

#Check for the filter parameter
RewriteCond %{QUERY_STRING} ^.*filter=([^&]+)&?.*$
RewriteRule ^(.*)$ $1/%1 [DPI]

#other parameters

RewriteRule ^(.*)$ index.php?/$1 [L]