Post rows to server
Post rows to server
 shamca            
            
                Posts: 3Questions: 2Answers: 0
shamca            
            
                Posts: 3Questions: 2Answers: 0            
            This is probably a very simple problem, but I couldn't find a api to post JSON to a URL.
I have a small table to which I copy rows;
I would like to be able to post the rows to my server in JSON format.
var table2 = $('#example2').DataTable({
        "paginate": false,
        "sort": false,
        "bInfo": false,
        "rowId": 'id',
        "search": {
            "caseInsensitive": true
        },
        "initComplete": function(settings, json) {
            console.log('init is complete')
        },
        "columns": [
            {item: "","width": "50px"},
            {item: "ID","width": "50px"},   // item id
            {item: "Name","width": "225px"}, // customer name
            {item: "Description","width": "200px"}, // description
            {item: "Size","width": "60px"}, // size
            {item: "Price","width": "75px"},    // real price
            {item: "Days","width": "75px"}  // days in store
        ],
        columnDefs: [
            {title: "Select", orderable: false, className: 'select-checkbox', targets:   0},
            {name: "id", data: "id", orderable: false, targets:   1},
            {name: "name", data: "name", orderable: false, targets:   2},
            {name: "description", data: "description", orderable: false, targets:   3},
            {name: "size", data: "size", orderable: false, targets:   4},
            {name: "price", data: "price", orderable: false, targets:   5},
            {name: "days", data: "days", orderable: false, targets: 6}
        ],
        select: {
            style:    'multi',
            selector: 'td:first-child'
        },
        order: [[ 1, 'asc' ]]
    });
I would appreciate any assistance with this.
Thanks,
Shaun McArthur
This question has an accepted answers - jump to answer
This discussion has been closed.
            
Answers
There nothing built into Datatables to post data to a server. You would use jQuery ajax for this using the
dataoption for the row data you want to post.You would use
row().data()orrows().data(), along withtoArray()to get the desired rows. JSON.stringify() would be used to convert this data to a JSON string.Kevin
Perfect, thank you!