How to fill a select field with data from the row

How to fill a select field with data from the row

ghherlinghherlin Posts: 20Questions: 3Answers: 0

Hallo, all

I have an Editor with rows containing several "select" fields, and their content depends on outside conditions known by the server application.

I'd also like to avoid having several round-trips, and so, would like to package the select options within the row data (possibly as a hidden field). Of course, when the row is refreshed (following an update), the same hidden field may be updated, etc..., etc...

I have sought wisdom in the Discussions, but have found nothing that yells at me: "try this".

Any ideas from your end?

Thanks in advance
George

Replies

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    Why would you like to avoid having "several round-trips"?

    Editor allows you to retrieve only one set of options for all of the records retrieved.

    There are two ways around this:
    a) you retrieve the options with an MJoin and update the options client side on "select" of the record to be edited. The MJoin-field could be hidden on the client side.
    b) You make an ajax call retrieving the options on "select" of the record to be edited or on Editor "open" and update the options client side.

    I prefer version b). It reduces the amount of data on initial load compared with a) and is hence faster because the ajax call on "select" won't delay anything.

    I only seem to have really complicated stuff in my code. So this is some code that populates the options of field "vat_qa.vat_option" and other things. It is done on Editor "open" in case the action is "edit":

  • ghherlinghherlin Posts: 20Questions: 3Answers: 0

    "Why would you like to avoid having "several round-trips"?": in a word: latency.

    "Editor allows you to retrieve only one set of options for all of the records retrieved.": that's what I thought.

    I found a way around this problem, adding data to initialise the selectize object in the json returned to fill the datatable. It is all rather special, but it works...

    All the best,

  • allanallan Posts: 61,436Questions: 1Answers: 10,049 Site admin

    Assuming that you are able to populate the options needed per row (if I've understood correctly), then you could use initEdit to know when you are in edit mode, use ids() to get the id of the row(s) being edited and then look up the data object for that row in the DataTable with row().data(). Then (finally!) use field().update() to populate the options for the field(s).

    It sounds a little convoluted, but I think it would be relatively straightforward to implement if you have the options you want to show in the data object for the row already. The downside to that of course is a potentially much larger initial data load, particularly if there are a lot of options for each row. The other worry would be keeping them in sync with the server - can an edit on one row effect the options shown on another row?

    Allan

Sign In or Register to comment.