我有我的網格(我使用與數據源相同的目錄中的XML文件)以下代碼。jqGrid第一次加載排序
var handsetGrid = $("#products").jqGrid({
url: 'catalog.xml',
datatype: "xml",
colNames:["SKU", "Name", "Brand", "Description", "Metadescription"],
colModel:[
{name:"sku", key: true, index:"sku", width:100, xmlmap:"sku", align:"right", sortable:true},
{name:"Name", index:"Name", width:300, sortable:true, xmlmap:">name>en"},
{name:"Brand", index:"Brand", width:100, sortable:true, xmlmap:"brand"},
{name:"description", index:"description", width:400, classes:"desc1", xmlmap:"description1>en", formatter:descFormatter},
{name:"metadescriptionEn", index:"metadescriptionEn", width:400, classes:"desc1", xmlmap:"metadescription>en", formatter:descFormatter}
],
width: 1300,
height:480,
shrinkToFit:false,
rownumbers: true,
scroll: true,
rowNum:22,
ignoreCase: true,
viewrecords: true,
sortname: "Name",
sortorder: "asc",
sortable: true,
loadonce: true,
pager: "#pager",
caption: "Handsets",
xmlReader: {
root: "products",
row: "product",
repeatitems: false,
id: "sku"
},
loadComplete: function(data) {
// test whether we have initial loadind and the "data" has XML type
if (data.nodeType) {
myXMLdata = data; // save original XML data
}
},
subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id) {
var subgrid_table_id;
subgrid_table_id = subgrid_id + "_t";
jQuery("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table>");
jQuery("#" + subgrid_table_id).jqGrid({
datatype:'xmlstring',
datastr: myXMLdata,
colNames: [ 'Id', 'Name', 'Duration', 'Price'],
colModel: [
{name:"ppid",index:"ppid",width:80, xmlmap:">id"},
{name:"ppname",index:"ppname",width:150, xmlmap:">name>en"},
{name:"ppduration",index:"ppduration",width:85, xmlmap:">priceperduration>duration>en", formatter: durationFormatter},
{name:"ppprice",index:"ppprice",width:80, xmlmap:">priceperduration>price", formatter: priceFormatter}
],
gridview: true,
xmlReader: {
root: "products>product:has('sku:contains('"+row_id+"')')>priceplansavailable",
row: "priceplan",
repeatitems: false
}
});
}
});
$("#handsets").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:false,refresh:false});
$("#handsets").jqGrid('navButtonAdd',"#pager",{caption:"Search Bar", title:"Toggle Search Toolbar", buttonicon :'ui-icon-pin-s',
onClickButton:function(){
handsetGrid[0].toggleToolbar();
}
});
$("#handsets").jqGrid('navButtonAdd',"#pager",{caption:"Clear", title:"Clear Search", buttonicon :'ui-icon-refresh',
onClickButton:function(){
handsetGrid[0].clearToolbar();
}
});
$("#handsets").jqGrid('filterToolbar', {defaultSearch:'cn'});
我的問題是當我加載網格我想它已經排序爲列:名稱。 我預計這三個參數來工作:
- sortname: 「姓名」,
- 排序順序: 「ASC」,
- 排序:真實,
點擊列後它工作正常,只是第一種不工作(加載頁面後)。
它正常工作,是這樣的:如果(data.nodeType){ \t myXMLdata =數據; ()函數調用函數()函數調用函數調用setTimeout()函數調用setTimeout()函數。 } ... 1毫秒就足以使它工作。 感謝您的幫助。 – 2011-04-12 07:38:07
@ ruffp:不客氣! – Oleg 2011-04-12 07:54:35
想必'setTimeout'只是因爲數據來自文件? – 2011-04-12 19:23:43