How to send editor fields as a JSON format.

How to send editor fields as a JSON format.

Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

How do I need to send the editor fields as a JSON fromat. While creating,edit the record using editor datatables.

Replies

  • rf1234rf1234 Posts: 2,362Questions: 76Answers: 340

    You don't need to worry about this in case you use Editor on client and server side. That is one of the advantages using Editor.

  • allanallan Posts: 56,851Questions: 1Answers: 9,035 Site admin

    Just to add to that, if you are writing your own server-side code and want the data in the request body, you can do so by using the ajax.data option. The final example on that page shows how it can be done.

    Allan

  • Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

    In my payload data going like below

    data[4][zoneId]: 4
    data[4][name]: zone4
    data[4][description]: zone3 from file
    data[4][status]: Inactvie
    action: edit
    typeName: Zones

    I want like below

    zoneId : 4
    name: zone4
    description: zone3 from file
    status : Inactive
    action : edit
    typeName : Zones

    This is my Javascript editor code.
    Please help me I am struck here.

    editor = new $.fn.dataTable.Editor( {
    ajax: {
    url: extract_url('/rest/updateType'),
    data: { "_csrf": CSRF_TOKEN,typeName : 'Zones'}
    },
    table: "#zones-search-results",
    idSrc: 'zoneId',
    dataType: 'json',
    fields: [ {
    label: "ID :",
    name: "zoneId",
    type:"hidden",
    data :"zoneId"
    }, {
    label: "Name :",
    name: "name",
    data :"name"
    }, {
    label: "Description :",
    name: "description",
    data :"description"
    },
    {
    label: "Status :",
    name: "status",
    data : status,
    type: "select",
    }
    ]

    } );
    
  • rf1234rf1234 Posts: 2,362Questions: 76Answers: 340
    edited August 3

    If you make those changes you cannot use Editor on the server because Editor won't understand the modified format.

    In case you still want that you can change the format on "preSubmit" (see the example at the bottom):
    https://editor.datatables.net/reference/event/preSubmit

    Good luck!

    Here is an example from my own coding making modifications to the JSON to be sent to the server:

    table
        .on('preSubmit', function( e, d, action) {
            if ( typeof d.data !== 'undefined' ) {
                var key = Object.keys(d.data)[0];
                delete d.data[key].sub_exec_cashflow;
                delete d.data[key].sub_earmark;
                delete d.data[key].sub_proof_schedule;
            }
        })        
    
  • Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

    Thanks for your immediate reply,

    What ever you have given example its deleting data . But I want to send the data with key and value pair.

    Ex : name: zone4 - I want like this data to send to the server.

    Not Like this (data[4][name]: zone4) - Actually Its going like this.

    In my payload data going like below

    data[4][zoneId]: 4
    data[4][name]: zone4
    data[4][description]: zone3 from file
    data[4][status]: Inactvie
    action: edit
    typeName: Zones

    I want like below

    zoneId : 4
    name: zone4
    description: zone3 from file
    status : Inactive
    action : edit
    typeName : Zones

  • rf1234rf1234 Posts: 2,362Questions: 76Answers: 340

    What ever you have given example its deleting data . But I want to send the data with key and value pair.

    Just go ahead!

    Your question is a pure Javascript question, not a Datatables question. If you don't know how to modify or replace a data object that gets passed into an event handler I would advise you to ask this question on SO.

  • Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

    Thank you,

    I resolved the issue.

Sign In or Register to comment.