开发者

jQuery ajax filters on a sortable table in a Ruby on Rails application

I am looking for a tutorial or documentation on how to create sortable table with filters in Rails application without using any jQuery or rails plugins.

I want to use jQuery as javascript library and not prototype.

All what I found in the internet is 开发者_如何学Cusing one or the other jQuery plugin.


If you are using Rails 2.3.x, the searchlogic gem may do the trick.

A good starting tutorial is Ryan Bates's tutorial on searchlogic from railscasts.

Thenm you should read this tutorial (ordering, searching and pagination with searchlogic). Take look also on the searchlogic_example source code (where you have 3 examples: no AJAX, AJAX using Rails helpers, AJAX using jquery).


Initially I went along without ajax.

And finally the following railscast solved the ajax stuff.

http://railscasts.com/episodes/240-search-sort-paginate-with-ajax


You need to create a server side call (GET) to provide a portion of the table. It needs to understand (1) the sort order (2) page that is requested and page size. You can accomplish this will an index method that looks for parameters and something like will_paginate (although there are many plugins to help with this).

On the client side, with jQuery, you simply need to handle all the clicks the user might make. For example, if they can sort by clicking on a column label, attach a click handler to it and make a new server request for the data. You can write a single Javascript method to do this, but you need to figure out how you represent page number, sort etc. in Javascriptland.

Implementing "filters" is just an extension to this. I don't know exactly how you want the UI to work, but it is another input into your server-side call.

Ryan Bates has a few railscasts that will help with all aspects of this, but I don't know of one that combines it all.

Just take it one step at a time...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜