Thanks Edmund.

Currently table-plus allows a user to sort the data when he clicks on
the desired column. This means that the sort will be performed by the
controller, that parses the parameters in the HTTP request when the
user clicks in a column.

In my second example, the sorted set is provided through the
@memberships variable. This works fine when the page is loaded.

When the user adds a new member, triggering the refresh of the
memberships table, the Ajax request crashes as it faces an nil
@memberships variable.

I suspect that I need to override a controller method that is being
called by the Ajax request, but I don't know which one.

Thanks,
  Tiago Franco


On Dec 29, 3:12 pm, Edmund <[email protected]> wrote:
> Tiago,
>
> Can this be acoomplished by defining a sort order in the model?  When
> you do this, you effectively establish a default sort order for a set
> of data.
>
> For example:
> Assuming that your model has Championship having many Memberships so
> try:
> (in Championship model)
> has_many memberships, :through => :[whatever], :order => :scores
>
> Thus, if you had a view which showed a Championship and displayed a
> view of it's memberships, the memberships will be sorted by scores.
>
> Hope this helps.
>
> Edmund
>
> On Dec 29, 9:15 am, Tiago Franco <[email protected]> wrote:
>
> > Hi,
>
> > Can someone provide a hint on how to implement a sortable table-plus
> > that can be refreshed through ajax?
>
> > Thanks,
> >   Tiago Franco
>
> > GamaFranco wrote:
> > > Hello,
>
> > > I'm having trouble implementing the sortable rows on table-plus.
>
> > > The following table-plus is refreshed whenever a new member is added,
> > > but can not be sorted (at least I don't know how to implement the
> > > controller).
>
> > > <table-plus:memberships fields="user, score" part="members"/>
>
> > > <form:memberships.new update="games, members" reset-form refocus-form>
> > >   Add a member:<name-one:user complete-target="&@championship"
> > > completer="new_member_name"/>
> > > </form>
>
> > > Changing the memberships to an instance variable allows the controller
> > > to process the sort order, but throws an exception whenever a member
> > > is added.
>
> > > The view:
>
> > > <table-plus with="&@memberships" fields="user, score" part="members"/>
>
> > > <form:memberships.new update="games, members" reset-form refocus-form>
> > >   Add a member:<name-one:user complete-target="&@championship"
> > > completer="new_member_name"/>
> > > </form>
>
> > > The controller:
>
> > > def show
> > >     @championship = find_instance
> > >     @memberships = @championship.memberships.apply_scopes(:order_by
> > > => parse_sort_param(:score))
> > > end
>
> > > Unfortunately whenever the user adds a new member, the ajax call can
> > > not refresh the table because @memberships is nil.
>
> > > What's the correct way to implement this?
>
> > > Thanks,
> > >   Tiago Franco
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to