[Solved] Can't get data using mData

[Solved] Can't get data using mData

k_sumitk_sumit Posts: 2Questions: 1Answers: 0
edited October 2014 in Free community support

This is my JS:

var table = $('#exampleTable').dataTable( {
                    "bFilter": true,
                    "processing": true,
                    "serverSide": true,
                    "fnDrawCallback": function ( oSettings ) {
                        if ( oSettings.bSorted || oSettings.bFiltered )
                        {
                            for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
                            {
                                $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
                            }
                        }
                    },
                    "aoColumnDefs": [
                        { "bSortable": false, "aTargets": [ 0 ] }
                    ],
                    
                    "oLanguage": {
                    "sSearch": "Quick Global Search: "
                    },
                    "sAjaxSource": "response.php",
                    "sAjaxDataProp": "",
                    "aoColumns": [
                    { "mData": null },
                    { "mData": "key" },
                    { "mData": "from_date" , "mRender":function(data){
                                                            return $.datepicker.formatDate('dd M, yy', new Date(data));;
                                                        }},
                    { "mData": "to_date" , "mRender":function(data){
                                                            return $.datepicker.formatDate('dd M, yy', new Date(data));;
                                                        }},
                    { "mData": "status" }
                ]
                });

This is my JSON:

{"sEcho":"3","iTotalRecords":4,"iTotalDisplayRecords":4,"aaData":[{"id":"2","key":"acUMNj2CZ7IEAAQRv01fLrCENeIbsjKZ21339220","from_date":"2014-10-07","to_date":"2014-10-30","status":"Unused"},{"id":"3","key":"GcDA3MGQ0gFLCWbFcjQibTBf1VVz5sC221922414","from_date":"2014-10-07","to_date":"2014-10-21","status":"Unused"},{"id":"4","key":"kWkMOa4F7SsvwqrjRsdSWlTqIhiaR5L721961883","from_date":"2014-10-06","to_date":"2015-04-03","status":"Unused"},{"id":"5","key":"3h7ih2XDZslvHPjVuhEVEogteb2B3Y2a22017762","from_date":"2014-10-01","to_date":"2015-09-30","status":"Unused"}]}

Previously I was not passing the sEcho, iTotalRecords and iTotalDisplayRecords in JSON, just simple array. That time it table was populating correctly, but page numbers and records number were not correct. So I made the Json like above. But now its not working.

DataTables warning: table id=exampleTable - Requested unknown parameter '0' for row 0. For more information about this error, please see http://datatables.net/tn/4

Any guidance will be very helpful as I am new to the datatables and learning things about it.

Answers

  • k_sumitk_sumit Posts: 2Questions: 1Answers: 0

    I removed "sAjaxDataProp": "" from JS.

    Problem solved. :D

This discussion has been closed.