how to modify data to be presented by Editor

how to modify data to be presented by Editor

riixriix Posts: 13Questions: 7Answers: 0
edited March 2020 in Editor

use case: datatable displays rows of Orders. Each order has a property called "hasRMA" (return merchandise authorization), and each table row has a button - either "CreateRMA" or "EditRMA", which is bound to this property. Editor is to be used to Create or Edit RMA. However there is no RMA object in the Order object; instead for Create - an RMA object is to be (new'ed) and attached to the Order as a new RMA property. I was hoping to do this in the "preOpen," by finding tbl.row(editor.modifier()).data() which does get me to the Order object for this row. But adding a new RMA property doesn't do anything (doesn't show up in the Editor).

SO: how can I modify the object that the Editor is about to present?

Answers

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

    There is a data tables event (not an editor event) that might be useful even for manipulating the potential input for Editor.
    https://datatables.net/reference/event/xhr

    You might use it to routinely add the ("empty") RMA object to every table row so that it exists as soon as Editor is being opened.

    My use case for this is the manipulation of Editor select options:

    table
    .on('xhr', function( e, settings, json, xhr ) {
        if (isBroker) {
            if ( json != null ) {
                if ( typeof json.options !== 'undefined' ) {
                    var ol = json.options["contract.some_id"];
                    var i = 1;
                    while ( ol[i] ) { //make the ordered labels unique (name, city)!!
                        if ( ol[i-1].label.replace(/\s+/g, '') === ol[i].label.replace(/\s+/g, '') ) {
                            ol.splice(i, 1);
                        } else {
                            i++;
                        }
                    }
                    json.options["contract.some_id"] = ol;
                }
            }
        }
    });
    
This discussion has been closed.