I'm trying to use DataTables with php and mysql. I have an ajax call that is pulling in data as such:
我正在尝试使用php和mysql的DataTables。我有一个ajax调用,它正在拉入数据:
[
{
"id": 3,
"ptid":"blah",
"last_name":"blah",
"first_name":"blah",
"priv_application":"E",
"priv_document":"E",
"priv_note":"E",
}
]
I'm configuring DataTables with the following:
我正在使用以下内容配置DataTables:
$('#listing').DataTable( {
"paging": false,
"searching": false,
"select": true,
ajax: {
url: '{{ url("administration/admindata") }}',
dataSrc: ''
},
columns: [
{ title: "ID" },
{ title: "PtID" },
{ title: "Last Name" },
{ title: "First Name" },
{ title: "Application" },
{ title: "Documents" },
{ title: "Notes" }
]
});
And the HTML for the table is as follows:
表格的HTML如下:
<table id="listing" class="display" width="100%"></table>
However, it doesn't want to load the data even though this configuration is exactly like the first example given here: https://datatables.net/manual/ajax
但是,它不想加载数据,即使此配置与此处给出的第一个示例完全相同:https://datatables.net/manual/ajax
I'm getting the following error: DataTables warning: table id=listing - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
我收到以下错误:DataTables警告:table id = listing - 第0行第0列请求的未知参数'0'。有关此错误的更多信息,请参阅http://datatables.net/tn/4
Any assistance is greatly appreciated.
非常感谢任何帮助。
2 个解决方案
#1
1
When using array of objects as your data source, you need to specify data source for each column using columns.data
option.
使用对象数组作为数据源时,需要使用columns.data选项为每列指定数据源。
$('#listing').DataTable( {
"paging": false,
"searching": false,
"select": true,
"ajax": {
"url": '{{ url("administration/admindata") }}',
"dataSrc": ''
},
columns: [
{ data: "id", title: "ID" },
{ data: "ptid", title: "PtID" },
{ data: "last_name", title: "Last Name" },
{ data: "first_name", title: "First Name" },
{ data: "priv_application", title: "Application" },
{ data: "priv_adocument", title: "Documents" },
{ data: "priv_note", title: "Notes" }
]
});
#2
0
Try something like this.
尝试这样的事情。
ajax": {
type': 'POST',
'url': "<?=action('TestController@postTestfunction')?>"
},
try to use the ajax call without blade template code. and make sure your route is written something like this.
尝试使用没有刀片模板代码的ajax调用。并确保你的路线写得像这样。
Route::controller('test', 'TestController');
Also try with change your controller function name "admindata" to "postAdmindata"
也可以尝试将控制器功能名称“admindata”更改为“postAdmindata”
Let me know still if you get stuck anywhere.
如果你被困在任何地方,请让我知道。
#1
1
When using array of objects as your data source, you need to specify data source for each column using columns.data
option.
使用对象数组作为数据源时,需要使用columns.data选项为每列指定数据源。
$('#listing').DataTable( {
"paging": false,
"searching": false,
"select": true,
"ajax": {
"url": '{{ url("administration/admindata") }}',
"dataSrc": ''
},
columns: [
{ data: "id", title: "ID" },
{ data: "ptid", title: "PtID" },
{ data: "last_name", title: "Last Name" },
{ data: "first_name", title: "First Name" },
{ data: "priv_application", title: "Application" },
{ data: "priv_adocument", title: "Documents" },
{ data: "priv_note", title: "Notes" }
]
});
#2
0
Try something like this.
尝试这样的事情。
ajax": {
type': 'POST',
'url': "<?=action('TestController@postTestfunction')?>"
},
try to use the ajax call without blade template code. and make sure your route is written something like this.
尝试使用没有刀片模板代码的ajax调用。并确保你的路线写得像这样。
Route::controller('test', 'TestController');
Also try with change your controller function name "admindata" to "postAdmindata"
也可以尝试将控制器功能名称“admindata”更改为“postAdmindata”
Let me know still if you get stuck anywhere.
如果你被困在任何地方,请让我知道。