Requested unknown parameter '_id' from the data source for row
Requested unknown parameter '_id' from the data source for row
pboisso
Posts: 7Questions: 0Answers: 0
Hi,
Using sAjaxDataProp:"" in our dataTable. Works well for loading data through ajax.
Also using editor to interact with a REST api. Delete works well, but Create does not. Depending on how settings are set and data is returned from the server, we either get a "Requested unknown parameter '_id' from the data source for row" error message if we return created row using aaData or directly (as shown in example below) (property "_id" *is* in the data) or a "Uncaught TypeError: Cannot read property 'length' of undefined" if we only return something like 'true'.
Any idea what's wrong?
datatable:
[code]
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": {
"create": "POST http://mydomain/api/site",
"remove": "DELETE http://mydomain/api/site/_id_"
},
"domTable": "#table_sites",
"dbTable": "sites",
"fields": [
{
"label": "{{col_name}}",
"name": "name",
"type": "text"
}
]
} );
$('#table_sites').dataTable( {
"sDom": "<'row-fluid'<'span4'l><'span4'T><'span4'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"bProcessing": true,
"sAjaxSource": 'http://mydomain/api/site/list',
"sAjaxDataProp": "",
"fnCreatedRow": function( nRow, aData, iDataIndex ) {
$(nRow).attr('id',aData["_id"]) //need this because server side data does not return DT_RowId
},
"aoColumnDefs": [
{ "aTargets": [0], "sTitle": "{{col_id}}", "mData": "_id" },
{ "aTargets": [1], "sTitle": "{{col_lang}}", "mData": "lang" },
{ "aTargets": [2], "sTitle": "{{col_theme}}", "mData": "theme" },
{ "aTargets": [3], "sTitle": "{{col_name}}", "mData": "name" },
{ "aTargets": [4], "sTitle": "{{col_type}}", "mData": "type" },
{ "aTargets": [5], "sTitle": "{{col_version}}", "mData": "version" },
{ "aTargets": [6], "sTitle": "{{col_created}}", "mData": "created" },
{ "aTargets": [7], "sTitle": "{{col_modified}}", "mData": "modified" }
],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );
[/code]
json returned on create:
[code]
{"name":"asdfasdfasdf2","type":"general","version":"1.0","theme":"client-planetebebe","created":1355865082,"modified":1355865082,"lang":"en-CA","_id":"ID:50d0dbfa3b8e77be4000000c"}
[/code]
Using sAjaxDataProp:"" in our dataTable. Works well for loading data through ajax.
Also using editor to interact with a REST api. Delete works well, but Create does not. Depending on how settings are set and data is returned from the server, we either get a "Requested unknown parameter '_id' from the data source for row" error message if we return created row using aaData or directly (as shown in example below) (property "_id" *is* in the data) or a "Uncaught TypeError: Cannot read property 'length' of undefined" if we only return something like 'true'.
Any idea what's wrong?
datatable:
[code]
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": {
"create": "POST http://mydomain/api/site",
"remove": "DELETE http://mydomain/api/site/_id_"
},
"domTable": "#table_sites",
"dbTable": "sites",
"fields": [
{
"label": "{{col_name}}",
"name": "name",
"type": "text"
}
]
} );
$('#table_sites').dataTable( {
"sDom": "<'row-fluid'<'span4'l><'span4'T><'span4'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"bProcessing": true,
"sAjaxSource": 'http://mydomain/api/site/list',
"sAjaxDataProp": "",
"fnCreatedRow": function( nRow, aData, iDataIndex ) {
$(nRow).attr('id',aData["_id"]) //need this because server side data does not return DT_RowId
},
"aoColumnDefs": [
{ "aTargets": [0], "sTitle": "{{col_id}}", "mData": "_id" },
{ "aTargets": [1], "sTitle": "{{col_lang}}", "mData": "lang" },
{ "aTargets": [2], "sTitle": "{{col_theme}}", "mData": "theme" },
{ "aTargets": [3], "sTitle": "{{col_name}}", "mData": "name" },
{ "aTargets": [4], "sTitle": "{{col_type}}", "mData": "type" },
{ "aTargets": [5], "sTitle": "{{col_version}}", "mData": "version" },
{ "aTargets": [6], "sTitle": "{{col_created}}", "mData": "created" },
{ "aTargets": [7], "sTitle": "{{col_modified}}", "mData": "modified" }
],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );
[/code]
json returned on create:
[code]
{"name":"asdfasdfasdf2","type":"general","version":"1.0","theme":"client-planetebebe","created":1355865082,"modified":1355865082,"lang":"en-CA","_id":"ID:50d0dbfa3b8e77be4000000c"}
[/code]
This discussion has been closed.
Replies
[code]
// Return from server:
{
"id": "...",
"row": {
...
}
}
[/code]
See: http://editor.datatables.net/server/
So just returning the row object would probably not work as Editor is expecting a different format. Are you able to change how the server returns the JSON?
It would be nice to have Editor relax this constraint, and is something that I want to do with Editor - the trick is making it possible with the infinite combinations of JSON return formats that are possible!
Regards,
Allan