aaData on server is a numeric array, on client is "column":"value" associative array.
aaData on server is a numeric array, on client is "column":"value" associative array.
pierissimo
Posts: 5Questions: 0Answers: 0
Hi!
I have a problem, or better I would to understand this "magic".
I have this simple client side code:
[code]
var table = $('#document_search').dataTable({
"bProcessing": true,
"bServerSide": true,
'sAjaxSource' : base_url("ajax/get_json/documents_search") ,
'sPaginationType': 'full_numbers',
'bDestroy': true,
'aoColumns' : [
{'sTitle' : "document id","mData":'document_id'},
{'sTitle' : "paper id","mData":'paper_id'}
]
});
[/code]
and, on server side, I use IgnitedDatatables, https://github.com/IgnitedDatatables/Ignited-Datatables/.
Ok, when I process the request on server side, IgnitedDatatables returns me an array, where aaData array contain numerica arrays.
When I json_encode this object, on client, the arrays of rows in aaData are "magically" associative.
Server side :
[code]
"aaData": [
[
"4",
"170"
],
[
"5",
"280",
],
...
]
[/code]
on client, became associative:
[code]
"aaData": [
[
" paper_id" : "4",
"document_id" : "170"
],
[
" paper_id" : "5",
"document_id" : "280",
],
...
]
[/code]
I wonder, how? This seems to be related to use of "mData" in aColumns.
I have a problem, or better I would to understand this "magic".
I have this simple client side code:
[code]
var table = $('#document_search').dataTable({
"bProcessing": true,
"bServerSide": true,
'sAjaxSource' : base_url("ajax/get_json/documents_search") ,
'sPaginationType': 'full_numbers',
'bDestroy': true,
'aoColumns' : [
{'sTitle' : "document id","mData":'document_id'},
{'sTitle' : "paper id","mData":'paper_id'}
]
});
[/code]
and, on server side, I use IgnitedDatatables, https://github.com/IgnitedDatatables/Ignited-Datatables/.
Ok, when I process the request on server side, IgnitedDatatables returns me an array, where aaData array contain numerica arrays.
When I json_encode this object, on client, the arrays of rows in aaData are "magically" associative.
Server side :
[code]
"aaData": [
[
"4",
"170"
],
[
"5",
"280",
],
...
]
[/code]
on client, became associative:
[code]
"aaData": [
[
" paper_id" : "4",
"document_id" : "170"
],
[
" paper_id" : "5",
"document_id" : "280",
],
...
]
[/code]
I wonder, how? This seems to be related to use of "mData" in aColumns.
This discussion has been closed.
Replies
You've set mData so DataTables is expecting objects rather than arrays. DataTables however should not be converted one form to another - it should be throwing an error if you tell it to expect objects and give it arrays.
Please link to a page showing the issue so we can look at and debug it.
Allan