0

我能够通过对服务器的 php 调用来填充网格以及执行更新。我似乎无法构建一个兼具两者的网格。在下面的代码中,我有 url 和 editurl。两者都指向同一个php页面,但我认为这是必要的。在 php 页面上,我通过 POST 收集单元格的内容并将它们打印到文件中。我知道这段代码是准确的,因为当我将它与只保存数据并且不尝试使用 php 服务器调用填充的网格一起使用时它可以工作。作为 JQGrid 的新手,我不确定如何保存和发送数据。另请注意,我必须使用 datatype: 'local' 来保存数据,但我必须使用 datatype: 'xml' 来填充网格。也许这就是问题所在?

$("#list").jqGrid({
url:'functions.php',
datatype:'xml',
mtype:'POST',
colNames:['Label','Account_Num','Amount', 'Type Code', 'Record Code', 'Sequence','Actions'],
colModel :[
{name:'label', index:'label', width:150, align:'center', sortable:false, editable:true},
{name:'cntrct_id', index:'cntrct_id', width:150, align:'center', sortable:true},
{name:'amount', index:'amount', width:150, align:'center', sortable:false, editable:true},
{name:'type_cd', index:'type_cd', width:150, align:'center', sortable:false, editable:true},
{name:'rec_cd', index:'rec_cd', width:150, align:'center', sortable:false},
{name:'db_seq', index:'db_seq', width:150, align:'center', sortable:false},
{   name:'actions',
classes:'jg_actions',
formatter:"actions",
editable:false,
sortable:false,
resizable:false,
fixed:true,
width:120,
formatoptions:{
    keys:true,
    delbutton:true,
    onSuccess: function(response){

    },
},
},
],
editurl: 'functions.php',
postData: { 
action:'popGrid', 
sqlCount:sqlCount, 
sqlSelect:sqlSelect, 
sqlSelect2:sqlSelect2, 
label1:label1, 
label2:label2,},
onSelectRow: function(id){
    if(id && id!==lastSel){
        jQuery('#list').restoreRow(lastSel);
    jQuery('#list').editRow(id,true);
    lastSel=id;
    }
},

pager: '#pager',
rowNum:100,
rowList:[100,200,300,400,500,600,700,800,900,1000],
sortname: 'cntrct_id',
sortorder: 'desc',
viewrecords: true,
caption: 'Adjustments'
}); 


<?php

$label = $_POST['label'];
$cntrct_id = $_POST['cntrct_id'];
$amount = $_POST['amount'];
$type_cd = $_POST['type_cd'];
$rec_cd = $_POST['rec_cd'];
$db_seq = $_POST['db_seq'];
$myfile = "text.txt";
$fh = fopen($myfile,'a');
fwrite($fh,$label.' '.$cntrct_id.' '.$amount.' '.$type_cd.' '.$rec_cd.' '.$db_seq);
fclose($fh);


?>
4

1 回答 1

1

我认为您对 XML 与本地数据类型感到困惑。数据类型指定的内容是提供给网格的数据的来源。本地意味着您正在提供一个变量,其中包含来自客户端其他部分的数据,其中 XML 意味着您将从 URL 提供 XML 格式的数据。(服务器端进程)

您应该能够使用 Firebug/Chrome 来查看更新后网格发送的数据、格式以及去向。编辑后,您functions.php的网格中的帖子应重新加载,该重新加载反映了您的编辑对数据集的更改。

于 2013-02-11T19:19:09.033 回答