Hi All, A common requirement for database apps is to list data in a table with a row of filters in the header. This allows users to customize the listing by entering values in one or more filter fields. What would be the best way to implement this feature in Rails? I''ve got a set of input fields in the first row of a table corresponding to each column of the database table. Should I go ahead and manually construct an SQL query based on the values of the filter fields in the @params? or has this been solved already in a more elegant manner? Keep in mind that text fields may require the LIKE operator while others require =,> etc. Thanks for your suggestions
Have you looked at what TOAD does? It lets you pick the field, the operation and enter the values, then adds it to a box that you can also then write the WHERE clause yourself if needbe, or add the right parens, etc. then, just pass that WHERE clause in the right place in one of the Find methods in the controllers... Letting the app populate a TEXT field lets the more astute user properly code the clause. Otherwise, it lets you have a few simple controls to do simple one-liners or low-complexity multiple condition clauses (i.e., where x or y or z, compared to "where x or (y and b) and not (z or d)". Of course, I''m guessing that you''ll need to defend against SQL Injection attacks too... On 4/12/05, H M <airmalik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > A common requirement for database apps is to list data in a table with > a row of filters in the header. This allows users to customize the > listing by entering values in one or more filter fields. > > What would be the best way to implement this feature in Rails? I''ve > got a set of input fields in the first row of a table corresponding to > each column of the database table. Should I go ahead and manually > construct an SQL query based on the values of the filter fields in the > @params? or has this been solved already in a more elegant manner? > Keep in mind that text fields may require the LIKE operator while > others require =,> etc. > > Thanks for your suggestions > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Do you mean like this: http://kevin.is-a-geek.net/projects/livetable I''m still looking at making some general way of building these types of components.. to be able to generate one of these, with appropriate filters based on the validations would be great. Kevin http://kevin.is-a-geek.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I haven''t used TOAD but I''ve seen similar functionality in other DB manager apps. For my app, however, this kind of advanced functionality will be overkill. All I''d like to do is - for text fields add : field LIKE ''%value%'' - for numeric fields: field = value - for date fields: field = value, unless an operator (>,<) is provided. I was hoping something like this would already be available in Rails but it looks like I''ll have to roll my own solution. I''ll upload my solution here in case others are interested in using/improving it. Hammed
>Do you mean like this: http://kevin.is-a-geek.net/projects/livetableVery slick! I''m looking for similar functionality. I noticed you''re using client side sorting and filtering. My datasets are large enough that I''d have to use a paginator and do the sorting and filter on the server side. You may want to use regexps to allow partial matches on the name column (similar to the LIKE sql operator). Also, users expect to be able to do case insensitive searches. Hammed
I''m going to be looking at some large datasets as well.. and haven''t yet contemplated what to do about pagination vs. display thousands of rows (they can filter to see what they want.. ). The sorting on this one is actually done server side.. on a regular interval the server returns a big XML record that the client writes to screen.. I''m thinking about switching this up to use a RoR backend and return HTML from server (as per how RoR does AJAX). Right now my filtering is no good at all.. I''d like to have wildcard matches on text strings.. case insensitive.. and be able to specify a range or list of values for numeric cols. (ie. any machines having ports 80,22 or 21 open). Kevin On 4/13/05, H M <airmalik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > >Do you mean like this: http://kevin.is-a-geek.net/projects/livetable > > Very slick! I''m looking for similar functionality. I noticed you''re > using client side sorting and filtering. My datasets are large enough > that I''d have to use a paginator and do the sorting and filter on the > server side. > > You may want to use regexps to allow partial matches on the name > column (similar to the LIKE sql operator). Also, users expect to be > able to do case insensitive searches. > > Hammed >-- Kevin http://kevin.is-a-geek.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails