Kendo UI 在客户端运行。您的数据是服务器端的。将数据放入网格的唯一方法是通过服务器端函数传递它。
在您的情况下,使用 CodeIgniter,这非常简单。您的控制器需要提供包含 Grid 和所需 JavaScript 的页面。数据源的transport 的read 部分应指向提供数据的URL。
在您的情况下,该 URL 将指向 CodeIgniter 方法。假设您希望网格显示员工信息,read URL 将指向 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 框架)以使用 Kendo Grids,那就是使用 Kendo 的 DataSourceResult.php,您可以通过查看 Grid 演示并将源代码切换到 PHP 来找到它.
它处理 Ajax 请求,包括任何过滤、排序和分页,并以 Grid 所需的格式返回数据。
我对其稍作编辑,以便可以使用 CI 的 $this->load->library 方法加载它,并从配置文件中获取数据库设置。