Convert my Datatable to a JSON

Convert my Datatable to a JSON

oakmeseoakmese Posts: 9Questions: 4Answers: 0

Hi,

I want to know if it's possible ton convert the datas of my Datatable to a JSON ?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,995Questions: 26Answers: 4,888

    Use rows().data() with toArray() chained to get a Javascript array of rows. You can then use JSON.stringify() to convert to a JSON string. For example:

    var json = JSON.stringify( table.rows().data().toArray() );
    

    Kevin

  • oakmeseoakmese Posts: 9Questions: 4Answers: 0

    Tank you @kthorngren

  • oakmeseoakmese Posts: 9Questions: 4Answers: 0
    edited January 2023

    I have div,span, img... in my table, I think the best solution is to get the JSON from the export option of excel do you think it's possible ?

  • kthorngrenkthorngren Posts: 20,995Questions: 26Answers: 4,888
    Answer ✓

    The Excel format is in OpenXML and not conducive to obtaining the raw data.

    I would look at using rows().every() to iterate all the rows and build a new array with the manipulated data. Use a regular expression to remove the HTML tags from the appropriate columns. Stack Overflow is a good resource for regex expressions.

    I forgot to mention if you use ajax you can use ajax.json() to get the last fetched data.

    Kevin

  • oakmeseoakmese Posts: 9Questions: 4Answers: 0

    thank you @kthorngren

Sign In or Register to comment.