Returning JSON from server, No matching records found

Returning JSON from server, No matching records found

BluestoneBluestone Posts: 9Questions: 3Answers: 0
$(document).ready(function() {
    $('#hashesTable').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "../post.php",
            "type": "POST",
            "data": {"getValues": "1"}
        },
        "columns": [
            { "data": "one" },
            { "data": "two" },
            { "data": "three" },
            { "data": "four" }
        ]
    } );
} );

http://i.imgur.com/nWa5w6B.png

Any idea what I'm missing?
Not getting any errors or anything, it just won't populate the table.

Replies

  • BluestoneBluestone Posts: 9Questions: 3Answers: 0

    I managed to populate the table by adding a row.add in the success option.
    Perhaps there's a better way though?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Two issues I can see:

    1. Not all of the parameters required for server-side processing are being returned
    2. data should be an array of object (or an array of arrays). One item in the data array for each row.

    Allan

  • BluestoneBluestone Posts: 9Questions: 3Answers: 0
    edited June 2016

    I added my objects to the array and there's one object on each row
    http://i.imgur.com/4g1JPvK.png

    Still doesn't work, just says unknown parameter '0'.

    $('#subsTable').DataTable( {
    serverSide: true,
    ajax: {
    url: '../post.php',
    type: 'POST',
    data: {getSubs: 1, approved: 0}
    }
    } );

  • BluestoneBluestone Posts: 9Questions: 3Answers: 0

    Adding columns: [ ] back did the trick actually. I suppose there isn't a way to do this without setting the columns?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    No - if you want to use objects as the data source, you have to tell DataTables. Consider for example (and keep in mind that Javascript objects are unordered) - how would DataTables know to display the "username" property in column index 0 (or whatever) if you didn't tell it? For that reason, when using objects you have to use columns.data to tell DataTables.

    Allan

This discussion has been closed.