Remove aoColumns

Remove aoColumns

marcpiratmarcpirat Posts: 51Questions: 18Answers: 0
edited March 2014 in General
hi

on http://live.datatables.net/ i tested this

[code]
// Server-side processing with POST
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bLengthChange": true,
"bSort": false,
"bInfo": false,
"iDisplayLength": 10,
"bPaginate": true,
"bAutoWidth": true,
"bServerSide": true,
"sDom": '<"#thead"f>tipr',
"ajax": "/ssp/objects.php",
"aoColumns": [
{ "sTitle": "Firstname", "mData": "first_name" },
{ "sTitle": "Lastname", "mData": "last_name" },
{ "sTitle": "Office", "mData": "office" },
{ "sTitle": "Position", "mData": "position" },
{ "sTitle": "Salary", "mData": "salary" },
{ "sTitle": "Start date", "mData": "start_date" },
]
} );
} );
[/code]

[code]
<!DOCTYPE html>








DataTables - JS Bin






Name
LastName
Office
Position
Salary
Start date






[/code]

if i removed aoColumns i get
[quote]
DataTables warning: table id=example - An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 10' at line 5
[/quote]

if i put bsort to true and remove aoColumns i get

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

how to avoid to use aoColumns?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you want to use object based data, you have to use the `mData` option of aoColumns / aoColumnDefs. There is no other option since you must tell DataTables what property of the object belongs in each column. Otherwise, how is it going to know that `salary` belongs in column index 4?

    It looks like there is an error in my PHP scripts if you use:

    [code]
    "bSort": false,
    [/code]

    I'll look into this and get a fix committed. Thanks for flagging it up.

    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Fixed in this commit: https://github.com/DataTables/DataTablesSrc/commit/ccad156eb

    Example: http://live.datatables.net/fiwajay/1/edit

    Allan
  • marcpiratmarcpirat Posts: 51Questions: 18Answers: 0
    ok thank you i understand
This discussion has been closed.