how to change format of output

how to change format of output

mamadsolimamadsoli Posts: 15Questions: 3Answers: 0
edited November 23 in Free community support

Hello, we know datatables send output with this format:

columns[0][data]= first_name
columns[0][name]=
columns[0][searchable]= true
columns[0][orderable]= true
columns[0][search][value]=
columns[0][search][regex]= false

but I need this format for output:

columns[0].data= first_name
columns[0].name=
columns[0].searchable= true
columns[0].orderable= true
columns[0].search.value=
columns[0].search.regex= false

How to can change format in datatables.net JQuery ?

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Use ajax.data to change the format of the request sent to the server. Are you asking to change the format to JSON? If yes then see the last example in the ajax.data docs. Otherwise use ajax.data as a function to change to the desired format.

    Kevin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0
    edited November 23

    I can't understand. can you show me an example?
    sure JSON is good...
    but I want to send data with request parameter

    .../pagination?draw=1&columns[0].data=first_name&...

    I need an example for it

    thanks

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    As I said the last example in the ajax.data docs show how to convert the request to JSON. Here is the code from the example:

    new DataTable('#myTable', {
        ajax: {
            url: 'data.json',
            contentType: 'application/json',
            type: 'POST',
            data: function (d) {
                return JSON.stringify(d);
            }
        }
    });
    

    Kevin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0
    edited November 23

    Thank you very much

    Can I send data looks like this ? (parameter request)

    new DataTable('#myTable', {
        ajax: {
            url: '.../pagination',
            type: 'GET',
            data: function (d) {
                return draw=1&columns[0].data=first_name&...
            }
        }
    });
    
  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited November 23 Answer ✓

    You will need to use ajax.data as a function to manipulate the original format sent to the server to the format you want. There is nothing built into Datatables to convert the default parameters to the format you want.

    Kevin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0

    Thank you dear
    I have to remove [] and send them.

    thanks a lot

Sign In or Register to comment.