REST - Edit multiple

REST - Edit multiple

TronikTronik Posts: 120Questions: 27Answers: 1

Im using Editors REST interface which is working well.
Altough I need some help with the update/patch data being sent from Editor.

edit: {
                type: 'PATCH',
                url:  'api/update/_id_',
        data: function ( d ) {
        console.log(JSON.stringify( d['data'] ));
                return JSON.stringify( d['data'] );
        }

Which results in this json:

{
    "1": {
        "parent_product": {
            "name": "Product A",
            "id": 1
        },
        "sku": "item_1233"
    },
    "2": {
        "parent_product": {
            "name": "Product B",
            "id": 2
        },
        "sku": "item_1233"
    }
}

for 2 rows edited, what I need is one object with the actual data that has been edited, for example if parent product has been edited:

{
    "parent_product": {
        "name": "Product B",
        "id": "2"
    }
}

Also, for multiple-update the API requires all id's in the url comma-separated, like api/update/1,2
Is this possible to achieve?

Many thanks

This question has an accepted answers - jump to answer

Answers

  • TronikTronik Posts: 120Questions: 27Answers: 1

    I solved the first question regarding sending only one object containing only changed data by using:

      formOptions: {
        main: {
            submit: 'changed',
        },
    },
    

    And then:

    d['data'][Object.keys(d['data'])[0]]
    

    Yet to solve how to manipulate the URL to contain all rowids comma-separated
    Any thoughts appreciated

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    Yet to solve how to manipulate the URL to contain all rowids comma-separated

    It will do that automatically. See this example. It doesn't actually work, since my server-side REST example script doesn't allow for multi-row editing, but you'll be able to see in the network inspector in your browser that it will submit comma delimited ids:

    Allan

This discussion has been closed.