因此,我正在尝试创建一个简单的datatables项目,而不使用它们的服务器端处理。我包含了css,js和所有的东西,但是仍然不能让它工作。下面是我的代码:
HTML:
<table id="dataTableUsers" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Full Name</th>
<th>Nickname</th>
<th>Email</th>
<th>Contact</th>
<th>Receipt</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for r in results %}
<tr>
<td>{{r.first_name}} {{r.last_name}}</td>
<td>{{r.nickname}}</td>
<td>{{r.email}}</td>
<td>{{r.contact}}</td>
<td>
<!--<a href="/user/receipt/{{r.accountID}}">View Receipt</a>-->
<a data-backdrop="true" data-toggle="modal" href="/user/receipt/{{r.accountID}}" data-target="#myModal{{r.accountID}}">View Receipt</a>
</td>
<td>
{% if r.status == 0 %}
<a href="/user/{{r.accountID}}/activate">Activate</a>
{% else %}
<a href="/user/{{r.accountID}}/deactivate">Deactivate</a>
{% endif %}
</td>
</tbody>
</tr>
{% endfor %}
</table>
在我的php中:
$app->get('/user/admin/:team', function($team) use($app) {
$session = new \RKA\Session();
if($session->logged_in) {
if($session->type) {
$db = new db();
if($team == "all") {
$results = $db->select("accounts");
} else {
$app->redirect('/user/admin/all');
}
$app->render('adminpage.html', array(
'logged_in' => $session->logged_in,
'type' => $session->type,
'results' => $results
));
} else {
$app->redirect('/user/'.$session->logged_in);
}
} else {
$app->flash('msg', 'Please log in first.');
$app->flash('type', 'danger');
$app->redirect('/user/login');
}
});
包括:
$(document).ready(function() {
$('#dataTableUsers').dataTable();
} );
</script>
<link href="/assets/css/jquery.dataTables.css" rel="stylesheet">
<script src="/assets/js/jquery.dataTables.js"></script>
顺便说一句,我使用的是超薄框架和小枝。我获得了所有数据,但无法使数据表正常工作。排序,搜索和所有的事情。我想我得到了css设计,但是我不能让主要的数据表函数工作。
如何使数据表在不使用其服务器端处理的情况下工作?
发布于 2015-07-16 00:44:24
由于我的循环位置的原因,代码无法工作。新的html文件现在看起来如下所示:
<table id="dataTableUsers" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Full Name</th>
<th>Nickname</th>
<th>Email</th>
<th>Contact</th>
<th>Receipt</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for r in results %}
<tr>
<td>{{r.first_name}} {{r.last_name}}</td>
<td>{{r.nickname}}</td>
<td>{{r.email}}</td>
<td>{{r.contact}}</td>
<td>
<!--<a href="/user/receipt/{{r.accountID}}">View Receipt</a>-->
<a data-backdrop="true" data-toggle="modal" href="/user/receipt/{{r.accountID}}" data-target="#myModal{{r.accountID}}">View Receipt</a>
</td>
<td>
{% if r.status == 0 %}
<a href="/user/{{r.accountID}}/activate">Activate</a>
{% else %}
<a href="/user/{{r.accountID}}/deactivate">Deactivate</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
以前,我的</tbody>
标签在我的</tr>
上面,这是错误的。我还将{% enfor %}
移到了我的</tr>
标签下面。现在它确实起作用了。
https://stackoverflow.com/questions/31401088
复制