我正在尝试从网格发送过滤器,以便在应用过滤器的情况下导出excel文件。我是kendo的新手,我在将过滤器,页面,排序发送到控制器时遇到了困难。以下是我到目前为止的情况:
控制器
public JsonResult List([DataSourceRequest] DataSourceRequest request)
{
//generating list to send to the grid
return Json(list.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
查看
Html.Kendo().Grid(Model)
.Name("tokenList")
.Columns(columns =>
{
// columns for the model
})
.DataSource(d => d.Ajax()
.ServerOperation(true)
.Read(read => { read.Action("List", "Settings", null); })
)
.ToolBar(toolbar =>
{
toolbar.Template(
@<text>
<a href="@Url.Action("ExportToExcel", "Settings", new { page = 1, pageSize = "~", filter = "~", sort = "~" })" class="export" onclick="onDataBound()">EXPORT</a>
</text>
);
})
.DefaultSetupForApp(<-this adds filtering, sortable, pageable).
Render();
}
这是我获取参数的JS函数(我在其他地方看到了这段代码,我正在尝试调整它,这里是我认为需要帮助的地方)
function onDataBound(e) {
var grid = this;
// ask the parameterMap to create the request object for you
**I need some info on this part, nothing i found was very helpful**
var requestObject = (new kendo.data.transports["aspnetmvc-server"]({ prefix: "" }))
.options.parameterMap({
page: grid.dataSource.page(),
sort: grid.dataSource.sort(),
filter: grid.dataSource.filter()
});
// Get the export link as jQuery object
var $exportLink = grid.element.find('.export');
// Get its 'href' attribute - the URL where it would navigate to
var href = $exportLink.attr('href');
// Update the 'page' parameter with the grid's current page
href = href.replace(/page=([^&]*)/, 'page=' + requestObject.page || '~');
// Update the 'sort' parameter with the grid's current sort descriptor
href = href.replace(/sort=([^&]*)/, 'sort=' + requestObject.sort || '~');
// Update the 'pageSize' parameter with the grid's current pageSize
href = href.replace(/pageSize=([^&]*)/, 'pageSize=' + grid.dataSource.total());
//update filter descriptor with the filters applied
href = href.replace(/filter=([^&]*)/, 'filter=' + (requestObject.filter || '~'));
// Update the 'href' attribute
$exportLink.attr('href', href);
}
我只想将过滤器发送到控制器。你能救我吗?
答案 0 :(得分:1)
我设法做到了。我所要做的就是给var grid
正确的网格,如下所示:
var grid= $('#tokensList').data('kendoGrid');
答案 1 :(得分:0)
我这样做:
这是我的网格工具栏模板。
<a class="k-button" id="export" href="Equipment/Export?page=~&pageSize=~&filter=~&sort=~" title="Export to Excel">
<span class="k-print" />
</a>
如有任何问题,请告诉我。