如何获取jqgrid的所有ID(包括分页的ID)? [英] How to get all ID's of jqgrid including the paginated ones?

查看:133
本文介绍了如何获取jqgrid的所有ID(包括分页的ID)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JQuery的新手.

I'm a newbie to JQuery.

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

I'm trying to use the function listed here.

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

The mya=$("#list").getDataIDs(); // Get All IDs is listing the IDs that are only in the current view. However my grid is paginated one. How can I fetch all the IDs?

这是我的代码:

$(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 });

    });

推荐答案

您使用datatype: "json"而不使用loadonce:true.因此,服务器负责排序和分页.因此,我将在仅服务器代码中以CSV或XLSX格式实现导出. jqGrid没有有关数据ID完整列表的信息,也没有有关完整数据集的任何其他信息.您只需将window.location设置为新的URL.网址的服务器部分将生成CSV或XLSX,并将其返回到HTTP正文中,并将其他HTTP标头(例如Content-Type)设置为(对于XLSX,为"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd".对于XLS,则为"ms-excel";对于CSV,则为"text/csv";对于附件;文件名= youfilname.xslx",为"content-disposition"(另一个文件扩展名).在这种情况下,Web浏览器将使用相应的名称将数据保存在文件中,并针对相应的应用程序(例如Excel.exe)打开文件.

You use datatype: "json" without loadonce:true. So the server is responsible to sorting and pagination. So I would implement the export in CSV or XLSX in the server code only. The jqGrid has no information about the full list of data ids or any other information about the full dataset. What you can do is just set window.location to the new url. The server part of the url will generate the CSV or XLSX return it in the HTTP body and set additional HTTP headers like Content-Type to ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" for XLSX, "application/vnd.ms-excel" for XLS or "text/csv" for CSV) and "content-disposition" to "attachment; filename=youfilname.xslx" (of another file extension). In the case the web browser will save the data in the file with the corresponding name and open the file with respect of the corresponding application (Excel.exe for example).

这篇关于如何获取jqgrid的所有ID(包括分页的ID)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆