Convert json array to aadata format

my real-time array format is not interpreted by the datatables aaData format as values ​​passed by columns:

{
    "aaData": [
        {
            "startDate": "09/08/2010 12:00:00 AM",
            "endDate": "13/08/2010 12:00:00 AM",
            "runDate": "16/08/2010 12:00:00 AM",
            "clientId": "40272",
            "clientType": "C",
            "plannerName": "Adrian Mcfly",
            "plannerRegion": "s1",
            "contact": "Vera chaniqua",
            "email": " ",
            "interviewDate": "09/08/2010 12:00:00 AM"
        },
    ]
}

how to remove column id and display only values ​​so that i can read data as ajax call?

+3
source share
3 answers

EDIT 8/29/2012

Starting with version 1.9, you can disable the ability to have a root JSON property.

"sAjaxDataProp": "",

This is most likely what you will get with most JSON serializers.

Or tune it

"sAjaxDataProp": "myData",

In datatables 1.8, you can format your json as follows:

{
        "aaData": [
            {
                "DT_RowClass": "",
                "description": "",             
                "pkgLineTree": {
                    "treeId": {
                        "name": "Jacksonville"
                    }
                }              
            },
            {
                "DT_RowClass": "",
                "description": "",       
                "pkgLineTree": {
                    "treeId": {
                        "name": "Jacksonville"
                    }
                }         
            }

        ]
    }

And in your data properties add this

"aoColumns": [    
        {
            "mDataProp": "pkgLineTree.treeId.name"
        },  
        {
            "mDataProp": "shortname"
        },
        {
            "mDataProp": "description"
        }, 
        {
            "mDataProp": "lineStatus"
        }
        ],    
+7
source

, , JSON ( startDate, endDate,...), .

, , , , , .

, :

$('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "scripts/server_processing.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
        $.getJSON( sSource, aoData, function (json) { 
            /* --- Here is where we massage the data --- */
            /* if the variable "json" is just a string (I forgot) then evaluate it first into an object (download a json library)*/
            var aaData=[];
            $.each(json, function(index, object) {
                var aData=[];
                $.each(object, function(key, value) { 
                    aData.push(value); //be careful here, you might put things in the wrong column 
                });
                aaData.push(aData);
            }); 
            /* --- And after we're done, we give the correctly formatted data to datatables --- */  /* --- if "json" was a string and not an object, then stringify aaData first (object to json notation, download a library) --- */
            fnCallback(aaData)
        } );
    }
} );

});

, !

+1

Try using square brackets instead of opening / closing curly braces {and}. See my answer to this question for more details: datatables and json formatting error with php

0
source

Source: https://habr.com/ru/post/1794452/


All Articles