Editor, ajax-data

Editor, ajax-data

Lontar8Lontar8 Posts: 7Questions: 3Answers: 0

Hi, please help as i am Editing the table with Editor.

editor = new $.fn.dataTable.Editor({
ajax: {
edit: { type: 'PUT',
url: '/customer',
data: function ( d ) {
var ownData = {data: d.data[1]};
return JSON.stringify( ownData );}
},

the console output as follows:
{"data":{"0":"1","1":"","2":"423015","3":"...

BUT my servlet class need jason-formatted data as follow
[{"no":"1","col":"","row":"423015",....

Please help how to reformat editor data to match my servlet class?

thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,350Questions: 1Answers: 10,443 Site admin
    Answer ✓

    You can use the ajax.data option to transform the data from what Editor submits to that which your server-side requires.

    The parameters Editor sends are documented here.

    Allan

  • Lontar8Lontar8 Posts: 7Questions: 3Answers: 0

    Dear Allan,
    thank you for the direction, and the problem is solved.
    by reformatting (correcting "Fields") below:

    editor = new $.fn.dataTable.Editor({
    ajax: {
    edit: {
    type: 'PUT',
    url: '/customer',
    contentType: 'application/json',
    data: function ( d ) {
    var ownData = d.data[1];
    return JSON.stringify(ownData);}}},

    table: '#example',
    idSrc: '0',

    fields: [
    {label:'No :', name:'no', data:'0'},
    {label:'Notes :', name:'col', data:'1'},
    {label:'NoWo :', name:'row', data:'2'},
    ....]

    Thank you.

This discussion has been closed.