Editor question

Editor question

RickardEngbergRickardEngberg Posts: 6Questions: 3Answers: 0

Hello,

Don't know if this forum is for Editor as well, but I guess so. Anyway, I use datatables and editor in many of my projects, but when posting data (a new record or whatever) from editor to my back end, I would like to have that as a json construct rather than the format it comes in by default. I know there have been questions about this here, and I've read all I've found but it seems to me that it should be simpler to do that. Just set a a response type or something.

For instance, if I have two fields, CODE and NAME in a table, click new to open editor and enter MYCODE and MYNAME and click create I would get something like

action=create&data[0][CODE]=MYCODE&data[0][NAME]=MYNAME

but i could make much more (and easier) use of a response like

{"action":"CREATE","data":[{"CODE":"MYCODE","NAME":"MYNAME"},....]}

If there is a setting for editor to do this, I'd be very happy. If not, could someone supply me with as a complete example as possible as to how I could achieve this. In some of the threads Allan mentions one could use data() to do this, but I' not sure how as I'm ok at javascript, but it isn't really my primary language.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    I would like to have that as a json construct rather than the format it comes in by default.

    You can use the ajax.data option for that. Have a look at the last example on the ajax.data documentation page.

    Allan

  • RickardEngbergRickardEngberg Posts: 6Questions: 3Answers: 0

    Awesome, that's exactly what I wanted! Thanks.

This discussion has been closed.