Kendo UI在客户端运行。你的数据是服务器端的。将数据存入网格的唯一方法是通过服务器端函数传递数据。
在你的情况下,使用CodeIgniter,这是非常简单的。您的控制器需要提供包含网格和所需JavaScript的页面。数据源transport
的read
部分应该指向提供数据的URL。
在你的情况下,该URL将是一个CodeIgniter方法。假设您希望网格显示员工信息,read
网址将指向employees\gridread
(或其他)。
employees\gridread
方法将调用employees_model
来克服员工记录。然后它以JSON格式返回员工数据。控制器可能看起来像:
public function gridread()
{
$limit = $this->input->post('take',TRUE);
$offset = $this->input->post('skip',TRUE);
$sort = $this->input->post('sort',TRUE);
$filter = $this->input->post('filter',TRUE);
$data = $this->employees_model->GridRead($limit, $offset,$sort,$filter);
if ($data):
header("Content-type: application/json");
echo json_encode($data);
else:
// send server error
header("HTTP/1.1 500 Internal Server Error");
echo "Failed to read data!";
endif;
}
您需要在模型中的一个函数,处理$limit, $offset, $sort, $filter
值来返回请求的数据。
编辑:实际上,有一个更容易挂钩的CodeIgniter(或任何PHP框架)与剑道电网的工作方式,那就是用剑道的DataSourceResult.php
,你可以通过查看网格演示和切换源PHP找到。
它处理Ajax请求,包括任何过滤,排序和分页,并以Grid需要的格式返回数据。
我已经稍微编辑了它,以便它可以使用CI的$this->load->library
方法加载,并且它从配置文件中获取数据库设置。
来源
2013-04-25 11:31:02
Mat