First attempt at DataTables. Error: Requested unknown parameter '0' from the data source for row 0
First attempt at DataTables. Error: Requested unknown parameter '0' from the data source for row 0
Hi there
Can someone tell me what I am doing wrong here? I get the error above and null in all the columns and rows of my table. Am I using aoColumnDefs correctly?
my datatable call:
[code]
$('#libraryItemList').dataTable({
"bServerSide": true,
"sAjaxSource": "Library/IndexAJAX",
"bProcessing": true,
"aoColumnDefs": [
{ "sName": "Title", "aTargets": ["Title"] },
{ "sName": "PublicationYear","aTargets":["PublicationYear"] },
{ "sName": "Location","aTargets": ["Location"] },
{ "sName": "LibraryShelf","aTargets": ["LibraryShelf"] },
{ "sName": "Summary", "aTargets": ["Summary"] },
{ "sName": "Author", "aTargets": ["Author"] },
{ "sName": "Category", "aTargets": ["Category"]},
{ "sName": "ISBN", "aTargets": ["ISBN"] },
{ "sName": "ISSN", "aTargets": ["ISSN"] },
{ "sName": "BusinessGroup", "aTargets": ["BusinessGroup"] },
{ "sName": "Officer", "aTargets": ["Officer"] },
{ "sName": "InputtedOn", "aTargets": ["InputtedOn"] },
{ "sName": "LibraryUser", "aTargets": ["LibraryUser"] },
{ "sName": "IsElectronicDoc", "aTargets": ["IsElectronicDoc"] }
]
});
[/code]
the html table:
[code]
Title
PublicationYear
Location
LibraryShelf
Summary
Author
Category
ISBN
ISSN
BusinessGroup
Officer
InputtedOn
LibraryUser
isElectronicDoc
[/code]
The JSON i am trying to parse:
[code]
{"sEcho":"1",
"iTotalRecords":10,
"iTotalDisplayRecords":10,
"aaData":[{
"Title":"FIRST AID AT WORK: YOUR QUESTIONS ANSWERED",
"PublicationYear":1997,
"Location":"ELECTRONIC DOCUMENT",
"LibraryShelf":"ELECTRONIC DOCUMENT",
"Summary":"Ref IND[G]214L. Leaflet to answer some basic questions about first aid provision at work.",
"Author":"HEALTH AND SAFETY EXECUTIVE",
"Category":"HEALTH AND SAFETY",
"ISBN":null,
"ISSN":null,
"BusinessGroup":"",
"Officer":"",
"InputtedOn":"\/Date(1242946800000)\/",
"LibraryUser":"LFJones",
"IsElectronicDoc":true
},
{
"Title":"NEED FOR OLD BUILDINGS TO BREATHE",
"PublicationYear":1987,
"Location":"SUBJECT SEQUENCE A-Z",
"LibraryShelf":"ARCHITECTURAL & HISTORIC BUILDINGS/CONSERVATION",
"Summary":"Information Sheet 4",
"Author":"SOCIETY FOR THE PROTECTION OF ANCIENT BUILDINGS",
"Category":"ARCHAEOLOGY/HISTORIC HERITAGE",
"ISBN":null,
"ISSN":null,
"BusinessGroup":"",
"Officer":"",
"InputtedOn":"\/Date(708649200000)\/",
"LibraryUser":"LFJones",
"IsElectronicDoc":false
}]}
[/code]
plus another 8 records
thanks for your time
Can someone tell me what I am doing wrong here? I get the error above and null in all the columns and rows of my table. Am I using aoColumnDefs correctly?
my datatable call:
[code]
$('#libraryItemList').dataTable({
"bServerSide": true,
"sAjaxSource": "Library/IndexAJAX",
"bProcessing": true,
"aoColumnDefs": [
{ "sName": "Title", "aTargets": ["Title"] },
{ "sName": "PublicationYear","aTargets":["PublicationYear"] },
{ "sName": "Location","aTargets": ["Location"] },
{ "sName": "LibraryShelf","aTargets": ["LibraryShelf"] },
{ "sName": "Summary", "aTargets": ["Summary"] },
{ "sName": "Author", "aTargets": ["Author"] },
{ "sName": "Category", "aTargets": ["Category"]},
{ "sName": "ISBN", "aTargets": ["ISBN"] },
{ "sName": "ISSN", "aTargets": ["ISSN"] },
{ "sName": "BusinessGroup", "aTargets": ["BusinessGroup"] },
{ "sName": "Officer", "aTargets": ["Officer"] },
{ "sName": "InputtedOn", "aTargets": ["InputtedOn"] },
{ "sName": "LibraryUser", "aTargets": ["LibraryUser"] },
{ "sName": "IsElectronicDoc", "aTargets": ["IsElectronicDoc"] }
]
});
[/code]
the html table:
[code]
Title
PublicationYear
Location
LibraryShelf
Summary
Author
Category
ISBN
ISSN
BusinessGroup
Officer
InputtedOn
LibraryUser
isElectronicDoc
[/code]
The JSON i am trying to parse:
[code]
{"sEcho":"1",
"iTotalRecords":10,
"iTotalDisplayRecords":10,
"aaData":[{
"Title":"FIRST AID AT WORK: YOUR QUESTIONS ANSWERED",
"PublicationYear":1997,
"Location":"ELECTRONIC DOCUMENT",
"LibraryShelf":"ELECTRONIC DOCUMENT",
"Summary":"Ref IND[G]214L. Leaflet to answer some basic questions about first aid provision at work.",
"Author":"HEALTH AND SAFETY EXECUTIVE",
"Category":"HEALTH AND SAFETY",
"ISBN":null,
"ISSN":null,
"BusinessGroup":"",
"Officer":"",
"InputtedOn":"\/Date(1242946800000)\/",
"LibraryUser":"LFJones",
"IsElectronicDoc":true
},
{
"Title":"NEED FOR OLD BUILDINGS TO BREATHE",
"PublicationYear":1987,
"Location":"SUBJECT SEQUENCE A-Z",
"LibraryShelf":"ARCHITECTURAL & HISTORIC BUILDINGS/CONSERVATION",
"Summary":"Information Sheet 4",
"Author":"SOCIETY FOR THE PROTECTION OF ANCIENT BUILDINGS",
"Category":"ARCHAEOLOGY/HISTORIC HERITAGE",
"ISBN":null,
"ISSN":null,
"BusinessGroup":"",
"Officer":"",
"InputtedOn":"\/Date(708649200000)\/",
"LibraryUser":"LFJones",
"IsElectronicDoc":false
}]}
[/code]
plus another 8 records
thanks for your time
This discussion has been closed.
Replies
I think the problem is with this line:
[code]
"aoColumnDefs": [
{ "sName": "Title", "aTargets": ["Title"] },
...
[/code]
and the other column definitions. What that line is telling DataTables is to apply the name 'Title' to columns which have a class of 'Title' on their header cell. You already have the title in place, and no class, so this isn't quite right. What I would suggest you want is actually:
[code]
"aoColumns": [
{ "mDataProp": "Title" },
...
[/code]
This blog post explains mDataProp in detail: http://datatables.net/blog/Extended_data_source_options_with_DataTables
Allan
Back to playing with paging and sorting now!
cheers
Ben