jqgrid,在asp.net-mvc站点中导出到excel(具有当前过滤器发布数据) [英] jqgrid, export to excel (with current filter post data) in an asp.net-mvc site
问题描述
我有一个asp.net-mvc网页,并且我在前端使用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).
我已经使用了工具栏过滤器,所以我看到过滤器设置存储在发布数据中,但是我不知道如何创建一种方法将所有过滤器设置/规则从jqgrid传递到服务器.
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.
我在谷歌搜索后看到了一堆jqgrid导出到excel"示例,但与该示例类似,它们似乎都没有将过滤器信息传递到服务器端.
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.
推荐答案
您可以在导出到Excel"表单中放置隐藏字段:
You could put hidden fields inside the Export to Excel form:
@using (Html.BeginForm(new { action = "ExportToExcel" }))
{
@Html.Hidden("sidx")
@Html.Hidden("sord")
@Html.Hidden("page")
@Html.Hidden("rows")
<table id="list"></table>
<input type="submit" value="Export to Excel" />
}
,并在提交表单时根据当前值填充它们:
and populate them upon form submission based on the current values:
$('form').submit(function () {
var grid = $('#list');
var sortname = grid.getGridParam('sortname');
var sortorder = grid.getGridParam('sortorder');
var page = grid.getGridParam('page');
var rows = grid.getGridParam('rowNum');
$('#sidx').val(sortname);
$('#sord').val(sortorder);
$('#page').val(page);
$('#rows').val(rows);
});
通过这种方式,ExportToExcel
控制器操作将采用这些参数并能够过滤列表.
This way the ExportToExcel
controller action will take those parameters and be able to filter the list.
这篇关于jqgrid,在asp.net-mvc站点中导出到excel(具有当前过滤器发布数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!