我正在尝试将jqGrid与Phalcon框架一起使用。我试图从表中获取数据并在jqGrid中显示它。我可以使用很多工作但是php变量中的数据不会出现在jqGrid中。我已经尝试了很多选项,看过jqGrid示例等。这些示例从mysql表中获取数据,因此有一个"url"
选项,其中指定了用于获取此数据的php文件。在Phalcon中,我无法将URL固定为伏特文件,该文件在运行中转换为php并执行,其次数据在变量中。我使用过echo json_encode($responce);
但它实际上回应了屏幕上的数据而不是在网格中显示它。 $responce
是包含json数据的变量。我正在使用Phalcon的volt
模板引擎生成'php'文件。下面代码中的大多数行都是php,而volt
行是直观的。完整的javascript和php在一个文件中。我可能会做一些不正确的事情,所以请原谅我对javascript& amp; AJAX。
我试图将数据显示在两个部分中,最重要的是发票中的主数据,jqGrid应显示行项目,即主数据的详细行。
以下是我的MVC结构Phalcon设置中目录edit.volt
的{{1}}文件的完整代码。我尝试将app\views\<mymodel>
用作datatype
,因为我的数据位于变量local
中,但它没有帮助。
$relOrderItem
除了顶部之外,上面代码的输出是json编码<script type="text/javascript">
$(document).ready(function () {
jQuery("#list4").jqGrid({
datatype: "json",
mtype: "post",
height: 'auto',
colNames:['ItemIid', 'Size', 'Colour', 'Position', 'Material', 'Amount', 'AmtRecvd'],
colModel:[
{name:'ro_relorder_item_iid', width:60, key:true, sorttype:"int"},
{name:'ro_relorder_size', width:90},
{name:'ro_relorder_colour', width:100},
{name:'ro_relorder_position', width:80, align:"right"},
{name:'ro_relorder_material', width:80, align:"right"},
{name:'ro_relorder_amount', width:80,align:"right",sorttype:"float"},
{name:'ro_relorder_amount_recvd', width:150}
],
pager: "#pager1",
rowNum: 10,
rowList: [10, 20, 30],
loadonce: true,
sortname: "ro_relorder_item_iid",
sortorder: "asc",
viewrecords: true,
gridview: true,
autoencode: true,
multiselect: true,
onSelectRow: function(id) {
var getID = $(this).jqGrid('getCell', id, 'ro_relorder_item_iid');
},
caption: "Detail Data"
})
});
jQuery("#list4").jqGrid('navGrid','#pager1',{edit:true,add:false,del:false});
</script>
{{ content() }}
{{ form("ro_relorder_t/save", "method":"post") }}
<ul class="pager">
<li class="previous pull-left">
{{ link_to("ro_relorder_t", " Go Back") }}
{{ link_to("ro_relorder_t/search", "Back To Search") }}
</li>
<li class="pull-right">
{{ submit_button("Save", "class": "btn btn-success") }}
</li>
</ul>
<div align="center">
<h3>Edit Release Order</h3>
</div>
<table>
<tr>
<td align="right"><label for="ro_relorder_iid">Relorder Iid</label></td>
<td align="left">{{ text_field("ro_relorder_iid", "type" : "numeric") }}</td>
<td align="right"><label for="ro_relorder_id">Relorder</label></td>
<td align="left">{{ text_field("ro_relorder_id", "type" : "numeric") }}</td>
<td align="right"><label for="ro_relorder_date">Relorder Date</label></td>
<td align="left">{{ text_field("ro_relorder_date", "size" : 30) }}</td>
</tr>
<tr>
<td align="right"><label for="ro_project_id">Project</label></td>
<td align="left">{{ text_field("ro_project_id", "size" : 30) }}</td>
<td align="right"><label for="ro_client_iid">Client Iid</label></td>
<td align="left">{{ text_field("ro_client_iid", "type" : "numeric") }}</td>
<td align="right"><label for="ro_client_contact">Client Contact</label></td>
<td align="left">{{ text_field("ro_client_contact", "size" : 30) }}</td>
</tr>
<tr>
<td align="right"><label for="ro_total_amt">Total Amt</label></td>
<td align="left">{{ text_field("ro_total_amt", "size" : 30) }}</td>
<td align="right"><label for="ro_advance_amt">Advance Amt</label></td>
<td align="left">{{ text_field("ro_advance_amt", "size" : 30) }}</td>
<td align="right"><label for="ro_balance_amt">Balance Amt</label></td>
<td align="left">{{ text_field("ro_balance_amt", "size" : 30) }}</td>
</tr>
<tr>
<td align="right"><label for="ro_employee_name">Employee Name</label></td>
<td align="left">{{ text_field("ro_employee_name", "size" : 30) }}</td>
<td align="right"><label for="ro_approval_recvd">Approval Recvd</label></td>
<td align="left">{{ text_field("ro_approval_recvd") }}</td>
<td align="right"><label for="ro_cancelled">Cancelled</label></td>
<td align="left">{{ text_field("ro_cancelled") }}</td>
</tr>
</table>
<div class="col-lg-12" style="height: 250px; overflow: scroll;">
<?php
if(!isset($_GET['page'])) $page=1;
else $page = $_GET['page'];
// get how many rows we want to have into the grid - rowNum parameter in the grid
if(!isset($_GET['rows'])) $limit=10;
else $limit = $_GET['rows'];
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
if(!isset($_GET['sidx'])) $sidx=1;
else $sidx = $_GET['sidx'];
// sorting order - at first time sortorder
if(!isset($_GET['sord'])) $sord="asc";
else $sord = $_GET['sord'];
$count = count($relOrderItemList) ;
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $limit*$page - $limit;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start < 0) $start = 0;
$responce = new stdClass();
$responce->total = $total_pages;
$responce->page = $page;
$responce->records = $count;
$i = 0;
?>
{% for relOrderItem in relOrderItemList %}
<?php
$responce->rows[$i]['id'] = $relOrderItem->getRoRelorderItemIid() ;
$responce->rows[$i]['cell'] = array($relOrderItem->getRoRelorderItemIid(), $relOrderItem->getRoRelorderSize(), $relOrderItem->getRoRelorderColour(), $relOrderItem->getRoRelorderPosition(), $relOrderItem->getRoRelorderMaterial(), $relOrderItem->getRoRelorderAmount(), $relOrderItem->getRoRelorderAmountRecvd() );
$i++;
?>
{% endfor %}
<?php
echo json_encode($responce);
?>
<table id="list4"><tr><td></td></tr></table>
<div id="pager1"></div>
</div>
{{ submit_button("Save", "class": "btn btn-success") }}</td
</form>
的内容,如下所示,还有一个空的jqGrid。如果我将它放在一个文本文件中并在jqGrid设置中指定为数据源,那么它将成功加载到jqGrid中。
$responce
How to load the JSON data into the Jqgrid?和Load local JSON data in jQgrid without AddJsonRows提供了一些提示,但实际代码不存在,因此我无法使其正常工作。任何使用像CodeIgniter,Yii,CakePhp,Zend等MVC框架和jqGrid的人都应该能够提出解决方案。
由于