【发布时间】:2013-08-28 18:45:37
【问题描述】:
我正在使用数据表插件来用我的数据格式化我的表。
- 我从控制器调用我的模型以收集所有数据。
- 我将数据数组发送到视图文件。
- 我在视图中使用 datatable 类启动了一个 table 标记,该类调用插件将常规 html 表转换为 datatables 表。
- 我检查以验证视图中的数组中是否有数据,然后如果有,我执行一个 foreach 循环来创建表行。如果没有数据,我会回显一串未找到数据。
我的问题是当有数据时它工作正常但是当没有数据时我收到Requested Unknown Parameter 1 from the data source for row 0 错误消息。
我之前见过其他人遇到过同样的问题,但是我看到的所有其他帖子都解释说他们在专门使用 datatables 插件时使用了 datatables json 数据。
关于如何防止显示此错误消息的任何想法。
<table class="dynamicTable table table-striped table-bordered table-condensed">
<thead>
<tr>
<th style="width: 1%;" class="uniformjs" id="checkboxth"><input type="checkbox" /></th>
<th class="center">ID</th>
<th>Name</th>
<th class="center">Date</th>
<th class="center" id="created_updated"></th>
<th class="right" id="actions">Actions</th>
</tr>
</thead>
<tbody>
<?php
//vardump($themes);
if (isset($themes) && is_array($themes))
{
foreach ($themes AS $theme)
{
echo '<tr class="selectable">';
echo '<td class="center uniformjs"><input type="checkbox" /></td>';
echo '<td class="center">' . $theme->id . '</td>';
echo '<td>' . $theme->name . '</td>';
if ($theme->updated_at != '0000-00-00 00:00:00')
{
echo '<td class="center" style="width: 80px;">' . date('d M Y', strtotime($theme->created_at)) . '</td>';
echo '<td class="center" style="width: 80px;"><span class="label label-block label-inverse">updated</span></td>';
}
else
{
echo '<td class="center" style="width: 80px;">' . date('d M Y', strtotime($theme->created_at)) . '</td>';
echo '<td class="center" style="width: 80px;"><span class="label label-block label-important">created</span></td>';
}
echo '<td class="center" style="width: 60px;">';
echo '<a href="' . base_url() . 'themes/edit/' . $theme->id . '" class="btn-action glyphicons pencil btn-success"><i></i></a>';
echo '<a href="' . base_url() . 'themes/delete/' . $theme->id . '" class="btn-action glyphicons remove_2 btn-danger"><i></i></a>';
echo '</td>';
echo '</tr>';
}
}
else
{
echo '<tr>';
echo '<td class="center" colspan="7">There are no themes. Select Add a New Theme.</td>';
echo '</tr>';
}
?>
</tbody>
</table>
这是主题附带的代码。
/* DataTables */
if ($('.dynamicTable').size() > 0)
{
$('.dynamicTable').dataTable({
"sPaginationType": "bootstrap",
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
}
});
}
【问题讨论】:
-
发布您的代码,否则我们无法帮助您!
-
您的数据表代码在哪里?调用数据表 api/功能的那个?那是给你这个错误吗?您是否有正在使用的阵列样本?是对象还是有对象的数组?
-
您是否在输出或控制台中收到此消息?
-
@chris 它在我的资产文件夹中。我只是不想在问题中放置太多代码并冒着得不到回答的风险。我的数据是一个对象数组。当表中没有可处理的数据时,会显示我的错误。
-
好吧..当我遇到这个问题时..我发现,有一个列混合匹配..通常在这种情况下定义的列比实际使用的多...但是因为你没有发布你的调用表的数据表特定 API/函数调用很难确定
标签: php javascript codeigniter datatables