我正在尝试使用AngularJS和CodeIgniter实现分页。
使用当前实现,所有记录都必须被提取一次。所以我想要的是实现它,以便在运行时可以从服务器一次一页地获取记录。当用户单击下一页时,应从服务器获取数据并显示。
这里我做的是客户端分页:
$scope.get_users = function()
{
$http.get("../admin/users/angular_all_users").success(function(data)
{
//$scope.allUsers = data;
/*-------------Pagination ALL USERS-----------------*/
$scope.tableParams = new ngTableParams(
{
page: 1,
count: 10,
sorting:
{
username: 'asc' // initial sorting
}
},
{
total: data.length,
getData: function($defer, params)
{
// use build-in angular filter for ordering
var orderedData = params.sorting() ?
$filter('orderBy')(data, params.orderBy()) : data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
/*-------------Pagination ALL USERS-----------------*/
}
以下是PHP控制器功能:
public function users_count()
{
$id=1;
$users_count=$this->vanesh_model->get_users_count($id);
print json_encode($users_count);
}
public function angular_all_users()
{
$id=1;
$data['all_users']=$this->vanesh_model->get_all_users($id);
print json_encode($data['all_users']);
}
这是我的观点:
<table ng-table="tableParams" class="table table-striped table-bordered table-hover" id="table_all_users">
<tbody ng-init="get_users()">
<tr class="gradeX" ng-repeat="user in $data | filter:query">
<td width="20%" data-title="'Select'">
<input type="checkbox" name="list[]" class="chk_all" value="" id="" onclick="uncheck_select_all(this);" />
</td>
<td width="35%" data-title="'User Name'" sortable="'username'">{{ user.username }}</td>
<td width="25%" data-title="'First Name'" sortable="'fname'">{{ user.fname }}</td>
<td width="25%" data-title="'Last Name'" sortable="'lname'">{{ user.lname }}</td>
<td width="15%" data-title="'Mobile'" sortable="'mobile'">{{ user.mobile }}</td>
<td width="15%" data-title="'Email'" sortable="'email'">{{ user.email }}</td>
<td width="15%" data-title="'Action'"><a title="Edit User" href="#/edit_user/{{user.user_id}}"><span class="fa fa-pencil"></span></a> | <a title="Delete User" id="" style="cursor:pointer;" ng-click="delete_user(user.user_id)"><span class="fa fa-trash-o"></span></a></td>
</tr>
</tbody>
</table>
如何在保持类似代码结构的同时实现这一点?我需要对代码进行哪些更改?
答案 0 :(得分:0)
您可以简单地将params作为查询字符串传递:
$http.get("../admin/users/angular_all_users", {params: {page: 1, pageSize: 10}}).success(function(data)
然后在Codeigniter中,你可以获得$_GET['page']
和$_GET['pageSize']
(或$this->input->get('page')
https://ellislab.com/codeigniter/user-guide/libraries/input.html)