JSON和过滤器与阿贾克斯的Zend框架输出,以数据表工作 [英] output of json and filter with ajax in zend framework to Make DataTables working
问题描述
我想实现jQuery的数据表到Zend框架1.我设立在控制器中的下列行动:
I am trying to implement jQuery DataTables into Zend Framework 1. I set up The following action in the controller:
public function getlistusersajaxAction()
{
$users = new Admin_Model_DbTable_User();
$param = $this->_request->getParam('filter','all');
$userLoggin = $this->_sessionUser->getIdentity();$results = ($param === 'all') ? $users->fetchAll()->toArray() : $users->fetchAll($users->select()->where('rankUser = ?', $param))->toArray();$json=Zend_Json::encode($results);
return $json;
和也在index.phtml以下code:
and also in the index.phtml the following code:
<script type="text/javascript">
$(document).ready(function() {
var table = $('#table-user').dataTable({
'info': false,
'ajax': '/<?=Zend_Registry::get('Zend_Locale')->getLanguage();?>/admin/UserManagement/getlistusersajax/filter/',
'sDom': 'lTfr<"clearfix">tip
});
现在的问题是,我有这样的错误:
The problem is that I have this error:
数据表警告:表中的id =表用户 - 阿贾克斯误差
DataTables warning: table id=table-user - Ajax error.
这表明装货,但不会有任何输出。我该如何解决这个问题?在此先感谢
It shows as loading, but gives no output. How can I fix this? Thanks in advance
推荐答案
您需要遵循一些步骤,同时返回 json_en code
数据。
You need to follow some steps while returning json_encode
data.
- 确保您检索到的数据和列
计数
应该是平等的。 - 确保在您的
声明
ID
表格
- Make sure you retrieved data and columns
count
should be equal. - Make sure to declare
id
in yourtable
样品例如为回报您的数据库
结果
Sample example for return of your database
results
$output = array(
'sEcho' => intval($sEcho),
'iTotalRecords' => $iTotal,
'iTotalDisplayRecords' => $iFilteredTotal,
'aaData' => array()
);
和jQuery中需要声明列
来显示这样的数据。
And in Jquery need to declare columns
to display data like this
$(document).ready(function() {
$('#table-user').dataTable({
'ajax':'yoururl',
// Some stuff
"aoColumns": [
{ "mData": "columnname" },
{ "mData": "columnname" },
------ ]
}); });
如果您使用的是服务器端
处理您可以使用sAjaxSource
而不是 AJAX
。它还将处理Request.For有关数据表中参数的详细检查了这链接
If you are using server-side
processing you can use "sAjaxSource"
instead of ajax
. It will also process the Request.For more details about datatable parameters check this link
下面是服务器端处理的使用PHP的例子。
Here is the example of server side processing using PHP.
这是不是我的你的问题的答案。这些信息有助于您解决problem.Thanks!
This is not my answer of your problem. This information help to you solve the problem.Thanks !
这篇关于JSON和过滤器与阿贾克斯的Zend框架输出,以数据表工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!