【问题标题】:how to select all records in the grid in order to export the data如何选择网格中的所有记录以导出数据
【发布时间】:2014-06-30 15:52:15
【问题描述】:

我正在尝试选择 jqgrid 表中存在的所有数据,以便导出到 excel 文件中。但是网格第一页中的数据只是被导出。即,如果网格中总共存在 25 条记录,并且第一页中存在 5 条记录,则仅导出前 5 条记录。

以下代码负责在网格的第一页中“仅”显示记录..

var gridData = $("#list").jqGrid('getRowData');

以下代码负责显示网格中所有页面中存在的记录..

var gridData1 =jQuery("#list").jqGrid('getGridParam','data');

如何使用上面的代码,以便我可以选择网格中存在的所有记录。另外,我正在尝试对网格中存在的记录应用过滤器。在这种情况下,如何获取过滤后的记录数以便导出它们..?

谢谢,

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    你可以在服务器端做。

    <script type="text/javascript">
    $(document).ready(function () {
        $('#list').jqGrid({
            caption: "test",
                 // ...
            }).navGrid(
                 // ...
                    }).jqGrid('navButtonAdd', '#pager', {
                        caption: "", buttonicon: "ui-icon-print", title: "export",
                        onClickButton: function () {
                            $("#list").jqGrid('excelExport', { url: 'path......' });
                        }
                    });
        });
    </script>
    

    excelExport方法,将当前页码、排序字段、过滤等发送到指定的url。现在您有时间处理这些参数并创建一个新的输出。

    【讨论】:

      【解决方案2】:

      您可能想尝试以下脚本和功能:

      var tableToExcel = (function () {
          var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
          return function (table, name) {
              if (!table.nodeType) table = document.getElementById(table)
              var ctx = { worksheet: name || 'Worksheet', table: table.outerHTML }
              window.location.href = uri + base64(format(template, ctx))
          }
      })();
      
      
      $(document).ready(function () {
          ...declare & setup the jqGrid with 'big row page', e.g. ...
              rowNum: 9999,
              rowList: [50, 100, 200, 9999],
          .........then add below navigation button after setup the grid...
          $("#list").jqGrid('navButtonAdd', pgrid1, {caption:"Download",title:"Download report contents", buttonicon :'ui-icon-circle-arrow-s',
              onClickButton:function(){
                  tableToExcel('list', 'export data')
              } 
          });
      

      }

      脚本>

      另外,另一种导出方式可以参考相关问题: How to enable jQgrid to Export data into PDF/Excel

      【讨论】:

      • 嗨,感谢您的建议.. 但我特别希望选择网格中存在的所有分页,即使在应用 过滤器 之后也是如此。如果我得到所有行,然后我想我可以用我的自定义导出按钮来处理它..仅供参考:我使用下面的 sn-ps 来应用过滤器:'function ApplyFilters { .... var myfilter = { groupOp: "AND",规则:[] }; var myfilterWithoutDateOROperation = { groupOp: "OR", rules: [] }; ...}' ...
      猜你喜欢
      • 2013-04-17
      • 2023-02-22
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多