简体   繁体   English

如何将过滤的剑道网格内容导入MVC控制器

[英]how to get filtered kendo grid contents into mvc controller

I have a Kendo Grid and after filter the grid, i want to export the available rows to export CSV Format.Filter is working well but when click export button the ajax call send all rows to controller. 我有一个Kendo网格,并且在对网格进行过滤之后,我想导出可用的行以导出CSV Format.Filter运行良好,但是当单击export按钮时,ajax调用会将所有行发送到控制器。 I need only the filtered row. 我只需要过滤的行。

Try like this, 这样尝试

  <div id="example" class="k-content">
      <button type="button"id="btnExport"  >Export to csv!</button>
<div id="grid"></div>
</div>

Script 脚本

<script>
$(function(){
 var grid = $("#grid").kendoGrid({
            dataSource: {
                type           : "odata",
                transport      : {
                    read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
                },
                schema         : {
                    model: {
                        fields: {
                            OrderID  : { type: "number" },
                            Freight  : { type: "number" },
                            ShipName : { type: "string" },
                            OrderDate: { type: "date" },
                            ShipCity : { type: "string" }
                        }
                    }
                },
                pageSize       : 10
            },
            filterable: true,
            sortable  : true,
            pageable  : true,
            columns   : [
                {
                    field     : "OrderID",
                    filterable: false
                },
                "Freight",
                {
                    field : "OrderDate",
                    title : "Order Date",
                    width : 100,
                    format: "{0:MM/dd/yyyy}"
                },
                {
                    field: "ShipName",
                    title: "Ship Name",
                    width: 200
                },
                {
                    field: "ShipCity",
                    title: "Ship City"
                }
            ]
        }).data("kendoGrid");

 $("#btnExport").click(function(e) {

 var dataSource =  $("#grid").data("kendoGrid").dataSource; 
     var filteredDataSource = new kendo.data.DataSource( { 
         data: dataSource.data(), 
         filter: dataSource.filter() 
     }); 

     filteredDataSource.read();
     var data = filteredDataSource.view();

     var result = "data:application/vnd.ms-excel,";

     result += "<table><tr><th>OrderID</th><th>Freight</th><th>Order Date</th><th>Ship Name</th><th>Ship City</th></tr>";

     for (var i = 0; i < data.length; i++) {
         result += "<tr>";

         result += "<td>";
         result += data[i].OrderID;
         result += "</td>";

         result += "<td>";
         result += data[i].Freight;
         result += "</td>";

         result += "<td>";
         result += kendo.format("{0:MM/dd/yyyy}", data[i].OrderDate);
         result += "</td>";

         result += "<td>";
         result += data[i].ShipName;
         result += "</td>";

         result += "<td>";
         result += data[i].ShipCity;
         result += "</td>";

         result += "</tr>";
     }

     result += "</table>";
     if (window.navigator.msSaveBlob) {
            window.navigator.msSaveBlob(new Blob([result]),'export.csv');
        } else {
            window.open(result);
        }


     e.preventDefault();
});
});
</script>

Demo : http://jsfiddle.net/SZBrt/236/ 演示http : //jsfiddle.net/SZBrt/236/

You can make a controller method and pass the grid's request as follows 您可以制作一个控制器方法,并按照以下方式传递网格的请求

public void Export([DataSourceRequest] DataSourceRequest gridRequest){
    // your logic goes here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Kendo网格多选项目获取到MVC控制器 - Get Kendo grid multi select items to MVC controller 获取Kendo Grid过滤的数据源计数 - Get Kendo Grid filtered datasource count 在Kendo网格的客户端中对网格进行过滤时,如何获取事件处理程序? - How to get the event handler when grid is filtered in client side in Kendo grid? Asp.net MVC在控制器中反序列化Kendo Grid数据 - Asp.net MVC deserialize Kendo Grid data in the controller 如何保存Kendo MVC网格的列顺序 - How to save Column Order of Kendo MVC Grid 在与Home Controller联系后kendo网格从GET变为POST的IIS服务器之间部署ASP.NET MVC 5应用程序 - Deploying ASP.NET MVC 5 app between IIS servers where kendo grid changes from GET to POST upon contacting Home Controller 如何使用Jquery在MVC中进行分页时从Kendo Grid UI中获取复选框选择的行值 - how to get the checkbox selected row values from Kendo Grid UI while pagination in MVC using Jquery 从jQuery MVC 4中的Kendo网格中获取复选框选中的行 - Get check box checked rows from Kendo grid in jquery MVC 4 如何从剑道网格内的剑道下拉列表中获取选定的值? - How to get the selected value from a kendo dropdownlist within a kendo grid? 如何从Kendo网格获取检查的行? - How to get checked rows from kendo grid?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM