jqgrid,在 asp.net-mvc 站点中导出到 excel(包含当前过滤器发布数据)
我有一个 asp.net-mvc 网页,我在前端使用 jqgrid 。我想要一个导出到 Excel 按钮,该按钮将导出当前的数据集(基于当前的过滤器)。
我已经使用工具栏过滤器,所以我看到过滤器设置存储在发布数据中,但我不知道如何创建一个方法,将所有过滤器设置/规则从 jqgrid 传递到服务器。
我在谷歌搜索后看到一堆 jqgrid“导出到 excel”示例,但 与此示例类似 ,他们似乎都没有将过滤器信息传递到服务器端。
i have an asp.net-mvc web page and i am using jqgrid on the front end. i want to have an export to excel button that will export the current set of data (based on the current filter).
i already use the toolbar filter so i see that the filter settings are stored in post data but i can't figure out how to create a method that will pass along all of the filter settings / rules to the server from jqgrid.
i see a bunch of jqgrid "export to excel" example after googling but similar to this example, none of them seem to be passing the filter information to the serverside.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将隐藏字段放入导出到 Excel 表单中:
并在表单提交时根据当前值填充它们:
这样,
ExportToExcel
控制器操作将采用这些参数并能够过滤列表。You could put hidden fields inside the Export to Excel form:
and populate them upon form submission based on the current values:
This way the
ExportToExcel
controller action will take those parameters and be able to filter the list.我所做的就是每次请求数据时将 gridstate 放入缓存中,然后使用 gridState 导出到 excel。 jqGrid 站点上有这样的示例:
然后当调用导出时:
}
这对我有用。
What I have done is put the gridstate into the cache each time data is requested, then I do the export to excel using the gridState. There are examples of this somewhere on the jqGrid site:
Then when the export is called:
}
This works for me.
我成功地进行了过滤导出,受到上述 @simpatric greg 解决方案的启发。
当请求数据时,我为每个网格参数设置一个会话变量,然后将它们再次传递到 Excel 导出服务。 Greg 的解决方案可以与 asp.net MVC 一起使用,这对于主要问题来说是可以的。以下解决方案也可以与标准纯js jqgrid一起使用:
CONTROLLER GRID ACTION
RECALLED INSIDE OF EXCEL EXPORT ACTION ^^
我希望这可能对遇到同样问题的其他人有所帮助使用标准 jqgrid。
I succeed to make filtered export, taking inspiration by above @simpatric greg solution.
I set one session variable for each grid parameter, when data is requested and then passing again them to the excel export service. Greg's solution can work with asp.net MVC, which is ok for the main question. The following solution could be used with standard pure js jqgrid too:
CONTROLLER GRID ACTION
RECALLED INSIDE OF EXCEL EXPORT ACTION ^^
I hope this may help for other people having the same problem with standard jqgrid.