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

jai*_*jai 3 jquery jqgrid

我是JQuery的新手.

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

mya=$("#list").getDataIDs(); // Get All IDs被列出了仅在当前视图的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 });

    });
Run Code Online (Sandbox Code Playgroud)

Ole*_*leg 6

datatype: "json"没有使用loadonce:true.因此服务器负责排序和分页.所以我服务器代码中实现CSV或XLSX中导出.jqGrid没有关于数据ID的完整列表的信息或有关完整数据集的任何其他信息.您可以做的只是设置window.location为新网址.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).