1

我已经看到了类似问题的答案,但它无济于事。正在显示网格,甚至正在传递数据,但唯一的问题是它没有在 jqGrid 中加载。我检查了浏览器中的响应,数据以 XML 格式发送。所以,唯一的问题是它没有在浏览器中显示。

var lastsel2;
            $(function(){ 
                  $("#list1").jqGrid({
                    //url:'process/roles/GetRoles1.php',
                    url: 'processDragonDisplay.php',
                    datatype: 'xml',
                    mtype: 'GET',
                    autowidth: true,
                    height: 'auto',

                    colNames:['name', 'body', 'active_flag','Action'],
                    colModel :[
                      {name:'name', index:'name',   search:true, sortable: true}
                      ,{name:'body', index:'body',  search:true, sortable: true}
                      ,{name:'active_flag', index:'active_flag', width:30, sortable: true}
                      ,{name: 'choice', index: 'choice',width: 50, sortable: false }

                    ],
                    pager: '#pager1',
                    rowNum:10,
                    rowList:[10,20,30],
                    sortname: 'name',
                    sortorder: 'asc',
                    viewrecords: true,
                    gridview: true,
                    caption: 'Templates',
                    editurl: 'processDragonDisplay.php',
                    onSelectRow: function(id) {
                        $('#rowID').html(id);
                        //$('#userId123').attr('value', id);
                        $('#list2').trigger("reloadGrid");
                        if(id && id!==lastsel2){
                            jQuery('#list1').restoreRow(lastsel2);
                            jQuery('#list1').editRow(id,true);
                              lastsel2=id;
                        }
                    },
                    loadComplete: function(){ 
                        var ids = jQuery("#list1").getDataIDs();
                        for(var i=0;i<ids.length;i++){ 
                            var cl = ids[i];
                            ce = "<span class='ui-icon ui-icon-pencil' onclick=editData('"+cl+"');></span>"; 
                            $("#list1").jqGrid('setRowData', ids[i] , { choice: ce });
                        }
                    }
                  }).navGrid("#pager1",{edit:false, add:false, del:true});
                  //$("#list1").jqGrid('inlineNav','#pager1', {edit:false, del: false, add: false});
                });

带有 XML 数据的响应:

<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><total>1</total><records>7</records><row id='A-000002'><cell>foo</cell><cell>bar yes ok</cell><cell>Y</cell><cell></cell></row><row id='A-000009'><cell>hello</cell><cell>hwq</cell><cell>Y</cell><cell></cell></row><row id='A-000013'><cell>nnnnn</cell><cell>nnnn</cell><cell>n</cell><cell></cell></row><row id='A-000007'><cell>t1</cell><cell>Your appointment for TOken  at  for  will be at </cell><cell>Y</cell><cell></cell></row><row id='A-000008'><cell>t1</cell><cell>Your appointment for TOken  at for  will be at </cell><cell>Y</cell><cell></cell></row><row id='A-000011'><cell>test2</cell><cell>test2</cell><cell>n</cell><cell></cell></row><row id='A-000015'><cell>wwwww</cell><cell>wwwww</cell><cell>g</cell><cell></cell></row></rows>
4

1 回答 1

1

您的 XML 数据格式无效。查看wiki中的一些示例。您必须使用 xmlReader 将 XML 数据映射到网格。

例如:

xmlReader: { root:"result", row:"invoice"  }

将是到以下数据格式的映射:

<invoices> 
   <request>true</request> 
   ... 
   <result> 
      <invoice> 
         <cell>data1</cell> 
         <cell>data2</cell> 
         <cell>data3</cell> 
         <cell>data4</cell> 
         <cell>data5</cell> 
         <cell>data6</cell> 
      </invoice> 
      ... 
   </result> 
</invoices>
于 2012-12-09T06:29:37.443 回答