Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Is there an event that I can use when saving a record from a ListGrid

    Let's say I have a grid for orders. Each order is linked to a customer. I'm using RubyOnRails server and I probably don't use SmartClient 100% optimal for "belongs to" relationships.

    The scenario I'm describing is not 100% the actual situation, but it should clarify the issue I'm facing right now.
    In the grid, I show the customer's name which is retrieved together with the order details. The SmartClient RestDataSource (and grid) treat the customer_name as field of the Order model. The SQL to retrieve this order would be something like:

    Code:
    SELECT orders.*, customer.name AS customer_name FROM orders INNER JOIN customers ON customers.id = orders.customer_id
    I want the user to be able to edit the customer's name directly from the orders grid. To the server the field "customer_name" is posted and there - with some trickery - I save the name of the customer via a Customer model.

    If the customer name is left empty, a validation error occurs and the server returns that error on the "name" field, because the customer model knows the field by its name "name" (not "customer_name"). The error is not shown in the grid, because that only knows "customer_name". I fixed this by changing (server-side) the object returned by the server to set the error on the "customer_name" field. Now the error icon shows in the grid, but when I hover it, an error in the console occurs. Further debugging shows the error string is null and therefore the asHTML() method can't be fired. A bit difficult to send screen dumps of everything so I try to formulate a concrete question.

    Is it possible to catch the moment the data gets returned (thus when the saving failed)? And can I then set the error client side? This way the server doesn't need to the trickery of changing the error field name and can I have this specific grid to do what it needs.

    Hopefully this explains the issue.

    #2
    Hi wallytax,

    there is RestDataSource.transformResponse(), which might help?

    Best regards
    Blama

    Comment


      #3
      Hi Blama, maybe. I do have individual - generated DataSource classes. Thus in my example a OrdersDataSource, subclassing RestDataSource. It is used on multiple locations, so I'm not sure if I can build this functionality on top of this generic approach, but I will give it a try. I tend to think it should be implemented in the grid, but maybe I can change the data source instance a bit.

      Thanks for the hint!

      Comment


        #4
        The grid indeed has an API for this, but that API is how the grid calls the DataSource, specifically, the DSRequest / DSResponse protocol.

        So the DataSource is the right place to put any kind of field renaming like this, and that’s how the SmartClient server does it, and is also how clientOnly DataSources do it (for the includeFrom feature).

        Comment

        Working...
        X