微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 如何获取jqgrid的所有ID,包括分页的ID?

我是 JQuery的新手.

我正在尝试使用here列出的功能.

mya = $(“#list”).getDataIDs(); //获取所有ID列出了仅在当前视图中的ID.但是我的网格是分页的.我如何获取所有ID?

这是我的代码

$(document).ready(function () {

    jQuery("#customer_list").jqgrid({
      url:'jq_customer_list',datatype: "json",colNames:['Col1','Col2','Col3'],colModel:[
{name:'Col1',index:'Col1',width:100},{name:'Col2',index:'Col2',width:80},{name:'Col3',index:'Col3',width:75},],rowNum:20,rowList:[5,10,20],mtype:"GET",rownumber:true,rownumWidth:40,pager: $("#customer_list_pager"),viewrecords: true,gridview: true,caption:"My Data",height: '50%',pagination:true

    }).navGrid('#customer_list_pager',{ search:true,del: false,add: false,edit: false,searchtext:"Search" },{},// default settings for edit
               {},// default settings for add
               {},// delete
               {cloSEOnescape: true,multipleSearch: true,closeAfterSearch: true },// search options
               {}
             ).navButtonAdd('#customer_list_pager',{
                 caption:"Export to Excel",buttonicon:"ui-icon-save",onClickButton: function(){ 
                   exportExcel($(this));
                 },position:"last"
             });

    function exportExcel($id){
        alert('excelExport');
          var keys=[],ii=0,rows="";
          var ids=$id.getRowData();  // Get All IDs
          var row=$id.getRowData(ids[0]);     // Get First row to get the labels
          for (var k in row) {
            keys[ii++]=k;    // capture col names
            rows=rows+k+"\t";     // output each Column as tab delimited
          }
          rows=rows+"\n";   // Output header with end of line
          for(i=0;i<ids.length;i++) {
            row=$id.getRowData(ids[i]); // get each row
            for(j=0;j<keys.length;j++) rows=rows+row[keys[j]]+"\t"; // output each Row as tab delimited
            rows=rows+"\n";  // output each row with end of line
          }
          rows=rows+"\n";  // end of line at the end
          var form = "<form name='csvexportform' action='excelExport' method='post'>";
          form = form + "<input type='hidden' name='csvBuffer' value='"+rows+"'>";
          form = form + "</form><script>document.csvexportform.submit();</sc"+"ript>";
          OpenWindow=window.open('','');
          OpenWindow.document.write(form);
          OpenWindow.document.close();
        }

    $("#customer_list").filterToolbar({autosearch:true });

    });

解决方法

您使用数据类型:“json”没有loadonce:true.因此服务器负责排序和分页.所以我只在服务器代码中实现CSV或XLSX中的导出. jqgrid没有关于数据ID的完整列表的信息或有关完整数据集的任何其他信息.你可以做的就是将window.location设置为新的url. url的服务器部分将生成CSV或XLSX将其返回到HTTP正文中,并将其他HTTP标头(如Content-Type)设置为(“application / vnd.openxmlformats-officedocument.spreadsheetml.sheet”for XLSX,“application / vnd. ms-excel“用于XLS或”text / csv“用于CSV)和”content-disposition“用于”attachment; filename = youfilname.xslx“(另一个文件扩展名).在这种情况下,Web浏览器将使用相应的名称将数据保存在文件中,并打开相应应用程序的文件(例如Excel.exe).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐