2013-04-14 92 views
0

我使用的jqGrid 4.4.5使用jQuery 1.9.1,並在服務器端,我使用ASP.NET MVC 4(雖然我不認爲這是部分的問題)。亞格數據的jqGrid不顯示4.4.5

我有一個簡單的jqGrid做工精細,而且我想一個簡單的分格添加到它。我已經配置了子網格,將它連接回服務器端的單獨控制器,並且一切看起來都很好,直到我需要顯示子網格數據爲止。

初始網格負載調用我的控制器的主要數據的方法,得到JSON和顯示的行。單擊+符號將展開一行,導致回撥到控制器的輔助數據方法。次要方法將子網格數據作爲有效的json返回(我使用Google Chrome開發工具對其進行了驗證)。子網格展開並顯示正確的行數和正確的標題,但值不出現在單元格中。

我已經通過了在線文檔和各種建議,在這裏,但似乎沒有奏效。我在jsonReader配置上玩了很多,但似乎沒有幫助(如果我將repeatitems設置爲true,它根本不起作用)。將gridview從真到假似乎也沒有幫助。

任何幫助表示讚賞。

這是對分格的控制器方法制成的實際調用:

/Schedule/SubGridData?nd_=1365975664423&id=1002200&InspectionScheduleId=1002200&ItemTypeId=1000003 

這是數據谷歌瀏覽器的權利要求是由調用返回:

{"rows":[{"cell":["Tony\u0027s HomeBrew","Icky Beer"]},{"cell":["Tony\u0027s WorkBrew","Tasty Beer"]}]} 

這是網格配置:

財產
<script type="text/javascript"> 
    jQuery(document).ready(function() { 
    jQuery('#GridDataBasic').jqGrid({ 
    autoencode:true, 
    autowidth:true, 
    caption:'Inspection Schedule', 
    datatype:'json', 
    jsonReader:{ repeatitems:false, id: 'InspectionScheduleId', subgrid: { root: 'rows', repeatitems: false, cell: 'cell', id: 'id' } }, 
    emptyrecords:'No record Found', 
    gridview:false, 
    height:'100%', 
    loadui:'block', 
    pager:'#pager', 
    rowList:[10,15,20,50], 
    rowNum:10, 
    rowattr: function(rowData) {var dueDate = new Date(parseInt(rowData.DueDate.substr(6)));var nowDate = new Date();var colorDate = new Date(dueDate - (rowData.RedOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'redOffsetColor'}; }colorDate = new Date(dueDate - (rowData.OrangeOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'orangeOffsetColor'}; }colorDate = new Date(dueDate - (rowData.YellowOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'yellowOffsetColor'}; }colorDate = new Date(dueDate - (rowData.GreenOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'greenOffsetColor'}; }}, 
    viewsortcols:[true,'vertical',true], 
    shrinkToFit:true, 
    url:'/Schedule/IndexGridData', 
    viewrecords:true, 
    subGrid: true, 
    subGridUrl : '/Schedule/SubGridData', 
    subGridModel : [ { 
    name : [ 'Item Name','Item Description' ], 
    width : [ 50,50 ], 
    align : [ 'left','left' ], 
    params : [ 'InspectionScheduleId','ItemTypeId' ] 
    } ], 
    colModel: [ 
    { 
     name:'InspectionScheduleId', 
     hidden:true, 
     key:true, 
     label:'InspectionScheduleId', 
     sortable:false, 
     index:'InspectionScheduleId' 
    },{ 
     name:'ItemTypeId', 
     hidden:true, 
     label:'ItemTypeId', 
     sortable:false, 
     index:'ItemTypeId' 
    },{ 
     name:'GreenOffsetInMinutes', 
     hidden:true, 
     label:'GreenOffsetInMinutes', 
     sortable:false, 
     index:'GreenOffsetInMinutes' 
    },{ 
     name:'YellowOffsetInMinutes', 
     hidden:true, 
     label:'YellowOffsetInMinutes', 
     sortable:false, 
     index:'YellowOffsetInMinutes' 
    },{ 
     name:'OrangeOffsetInMinutes', 
     hidden:true, 
     label:'OrangeOffsetInMinutes', 
     sortable:false, 
     index:'OrangeOffsetInMinutes' 
    },{ 
     name:'RedOffsetInMinutes', 
     hidden:true, 
     label:'RedOffsetInMinutes', 
     sortable:false, 
     index:'RedOffsetInMinutes' 
    },{ 
     name:'ItemTypeName', 
     label:'Item Type', 
     sortable:false, 
     index:'ItemTypeName' 
    },{ 
     align:'center', 
     name:'DueDate', 
     formatter:'date', formatoptions: {srcformat:'ISO8601Long', newformat:'m/d/Y H:i:s'}, 
     label:'Due Date', 
     sortable:true, 
     index:'DueDate' 
    } 
    ] 
    }); 
    }); 
    </script> 

回答

0

subgridjsonReader應包含repeatitems: true而不是falsesubgrid屬性的默認值爲alsready {root:"rows", repeatitems: true, cell:"cell"}。所以我認爲刪除subgrid屬性jsonReader應該可以解決你的問題。

+0

所以,這是它正是* * - 謝謝。主電網和子電網的重複值都是一樣的。主電網失敗,但子電網失敗。 – Tony

+0

@Tony:不客氣!我很高興,我可以幫助你。在回答關於'jsonReader'的問題時,我很喜歡它的使用是newcommer許多錯誤的來源。我發佈了trirand建議來實現JSON格式的自動檢測。這些建議現在是jqGrid的一部分。我會查看子網格的代碼來實現它。如果你使用jqGrid 4.4.5,你可以嘗試刪除完整的'jsonReader'。 'loadonce:true'的使用有一個錯誤,但是你不使用它。所以我認爲如果你只是刪除'jsonReader',你的網格將被成功填充。 – Oleg

+0

如果我刪除jsonReader,但是,我將如何告訴jqGrid我的哪些列表示唯一的行ID?我不希望jqGrid使用任意值並將其傳遞給我將來的任何定製。 – Tony

0

您在次網格數據將不會顯示(以及)如果不存在你給出的功能之一。所以,如果你犯了一個錯字空行會顯示:

afterSave: ReloadSubGrid, onError: UpdateFailed, delOptions:... 
... 
function ReloadSbuGrid(rowid, response) { 
    ... 
} 

錯字:ReloadSbuGrid應該已經ReloadSubGrid