我有一個帶有子網格的jqGrid。我想排序子網格,以便在子網格內按照排序順序顯示重要細節。JQGrid:根據某個鍵排序子網格值
排序順序:EBFNUM,VERSION & APPLIEDDATETIME
下面是一個屏幕截圖
可選:過濾器適用於elementName
,isPresentinXml1
& isPresentinXml2
。反正有沒有相同的過濾器可以工作name
,firstValue
& secondValue
(子網格列)?
代碼電網
_starHeader="infa9 windowsss";
_header1="infa9_windowss";
grid = jQuery("#ebfList");
grid.jqGrid({
datastr : compareEBFData,
datatype: 'jsonstring',
colNames:['EBF','',_starHeader, _header1],
colModel:[
{name:'elementName',index:'elementName', width:188},
{name:'subCategory',index:'subCategory',hidden:true, width:1},
{name:isPresentinXml1,index:isPresentinXml1, width:270, align:'center', formatter: patchPresent},
{name:isPresentinXml2,index:isPresentinXml2, width:270, align:'center', formatter: patchPresent}
],
pager : '#ebfGridpager',
rowNum:60,
rowList:[60,120,240],
scrollOffset:0,
height: 'auto',
autowidth:true,
viewrecords: false,
gridview: true,
loadonce:true,
jsonReader: {
repeatitems: false,
page: function() { return 1; },
root: "response"
},
subGrid: true,
// define the icons in subgrid
subGridOptions: {
"plusicon" : "ui-icon-triangle-1-e",
"minusicon" : "ui-icon-triangle-1-s",
"openicon" : "ui-icon-arrowreturn-1-e",
//expand all rows on load
"expandOnLoad" : false
},
loadComplete: function() {
if (this.p.datatype !== 'local') {
setTimeout(function() {
grid.trigger('reloadGrid');
}, 0);
} else {
$("#compareEBFDiv").show();
}
},
subGridRowExpanded: function(subgrid_id, row_id) {
var subgrid_table_id, pager_id, iData = -1;
subgrid_table_id = subgrid_id+"_t";
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' style='overflow-y:auto' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
$.each(compareEBFData.response,function(i,item){
if(item.id === row_id) {
iData = i;
return false;
}
});
if (iData == -1) {
return; // no data for the subgrid
}
jQuery("#"+subgrid_table_id).jqGrid({
datastr : compareEBFData.response[iData],
datatype: 'jsonstring',
colNames: ['Name','Value1','Value2'],
colModel: [
{name:"name",index:"name",width:70},
{name:firstValue,index:firstValue,width:100},
{name:secondValue,index:secondValue,width:100}
],
rowNum:10,
//pager: pager_id,
sortname: 'name',
sortorder: "asc",
height: 'auto',
autowidth:true,
jsonReader: {
repeatitems: false,
//page: function() { return 1; },
root: "attribute"
}
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',{edit:false,add:false,del:false});
}
});
grid.jqGrid('navGrid', '#ebfGridpager', { search: false, refresh: false });
grid.jqGrid('navButtonAdd',"#ebfGridpager",{caption:"Toggle",title:"Toggle Search Toolbar", buttonicon :'ui-icon-pin-s',
onClickButton:function(){
grid[0].toggleToolbar();
}
});
grid.jqGrid('navButtonAdd',"#ebfGridpager",{caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh',
onClickButton:function(){
grid[0].clearToolbar();
}
});
grid.jqGrid('filterToolbar',
{stringResult: true, searchOnEnter: false, defaultSearch: 'cn'});
JSON響應
{
"response": [
{
"id": "1",
"elementName": "EBF262323",
"category": "Product",
"subCategory": "EBFINFO",
"isEqual": false,
"isPrasentinXml1": true,
"isPrasentinXml2": true,
"isPrasentinXml3": false,
"attribute": [
{
"name": "APPLIEDDATETIME",
"firstValue": "Mon Sep 05 11:12:32 IST 2011",
"secondValue": "Mon Sep 05 11:12:32 IST 2011"
},
{
"name": "VERSION",
"firstValue": "9.1.0",
"secondValue": "9.1.0"
},
{
"name": "EBFNUM",
"firstValue": "EBF262323",
"secondValue": "EBF262323"
}
]
},
{
"id": "2",
"elementName": "EBF99993",
"category": "Product",
"subCategory": "EBFINFO",
"isEqual": false,
"isPrasentinXml1": true,
"isPrasentinXml2": true,
"isPrasentinXml3": false,
"attribute": [
{
"name": "APPLIEDDATETIME",
"firstValue": "Mon Sep 09 11:12:32 IST 2012",
"secondValue": "Mon Sep 09 11:12:32 IST 2012"
},
{
"name": "VERSION",
"firstValue": "9.1 HF2",
"secondValue": "9.1 HF2"
},
{
"name": "EBFNUM",
"firstValue": "EBF99993",
"secondValue": "EBF99993"
}
]
}
],
"xls_path": "/files/modifiedServices.xls"
}
UPDATE
我試圖像下面的代碼,我內心的網格內,但沒有效果
var orderOfEBFSubCategory = [
"EBFNUM",
"PRODUCT",
"VERSION"
];
{name:"name",index:"name",width:70,
sorttype: function (value) {
var order = $.inArray(value, orderOfEBFSubCategory);
return order;
}},
感謝您的演示答案。我在'$(document)中複製了你的整個代碼。準備好「我的項目,但它不排序..我可能會出錯? – abi1964 2012-04-01 10:53:39
@AbhishekSimon:您應該在調試器中檢查頁面:可能某些像'orderOfEBFSubCategory'這樣的變量未定義。您可以使用F12啓動IE Developer Tools,選擇「腳本」選項卡並單擊「開始調試」。您可以在'var order = $ .inArray(value,orderOfEBFSubCategory);'行上設置斷點並確認在打開子網格時調用'sorttype'。所以子格應該排序。您可以在演示和代碼上重複相同的步驟。我希望你能找到這個問題。 – Oleg 2012-04-01 11:06:27
謝謝,它的工作 – abi1964 2012-04-02 07:54:36