jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – jqGrid在第一次加载时排序大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的网格有以下代码(我在与数据源相同的目录中使用 XML文件).

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",xmlmap:"brand"},{name:"description",index:"description",width:400,classes:"desc1",xmlmap:"description1>en",formatter:descFormatter},{name:"MetadescriptionEn",index:"MetadescriptionEn",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,{name:"ppduration",index:"ppduration",width:85,xmlmap:">priceperduration>duration>en",formatter: durationFormatter},{name:"ppprice",index:"ppprice",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',{Caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh',onClickButton:function(){
        handsetGrid[0].clearToolbar();
    }
});

$("#handsets").jqGrid('filterToolbar',{defaultSearch:'cn'});

我的问题是当我加载网格时,我希望它已经为列排序:名称.
我期望使用这三个参数:

> sortname:“名称”,
> sortorder:“asc”,
> sortable:true,

单击列后它正常工作,只是第一个排序不起作用(加载页面后).

解决方法

如果使用“xml”或“json”之类的远程数据类型,则服务器负责提供已排序的数据.

如果你不能这样做,你可以在loadComplete中触发reloadGrid,但你应该使用setTimeout JavaScript方法来完成第一个加载过程.

要不进行递归,您应该将“reloadGrid”放在loadComplete的if(data.nodeTypE)块中.

更新:Free jqGrid有选项forceClientSorTing:true,它解决了这个问题.该选项允许在显示第一页之前强制对数据进行排序和过滤(如果设置了可选的postData.filters).

大佬总结

以上是大佬教程为你收集整理的jquery – jqGrid在第一次加载时排序全部内容,希望文章能够帮你解决jquery – jqGrid在第一次加载时排序所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。