【问题标题】:MVC Kendo Grid export to excel by clicking extenrally placed button通过单击外部放置的按钮将 MVC Kendo Grid 导出到 excel
【发布时间】:2015-07-14 04:39:28
【问题描述】:

我有一个特殊的场景可以在 Kendo-UI MVC Grid 上实现导出功能。

场景:我想将 Kendo MVC Grid 导出到 excel 表,但是当单击放置在 Grid 之外的按钮时,我不想显示或使用 Kendo 提供的默认导出到 excel 按钮,而是我想使用另一个 html 输入按钮。有人可以帮我吗?任何帮助将不胜感激。

【问题讨论】:

    标签: kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    请尝试以下代码 sn-p。

    <div id="grid"></div>
    <input type="button" onclick="downlaodexcel()" value="Export to excel" />
    <script>
        $("#grid").kendoGrid({
            dataSource: {
                type: "odata",
                transport: {
                    read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products"
                },
                pageSize: 10
            },
            sortable: true,
            pageable: true,
            columns: [
                { width: 300, field: "ProductName", title: "Product Name" },
                { field: "UnitsOnOrder", title: "Units On Order" },
                { field: "UnitsInStock", title: "Units In Stock" }
            ]
        });
    
        function downlaodexcel() {
            $("#grid").getKendoGrid().saveAsExcel();
        }
    </script>
    

    如果有任何问题,请告诉我。

    【讨论】:

    • 谢谢@Jayesh Goyani .. 你的代码在正确的位置,它对我来说也很完美。谢谢你。
    【解决方案2】:

    我知道自 Kendo UI Q3 2014 (2014.3.1119) 版本开始,Kendo 网格现在已内置导出。但是,如果您像我一样坚持使用旧版本并遇到 .saveAsExcel() 仅导出当前页面的事实,请尝试此操作。

    var dataSource = $("#grid").data("kendoGrid").dataSource;
    total = dataSource.total();
    dataSource.pageSize(total);
    $("#grid").getKendoGrid().saveAsExcel();
    dataSource.pageSize(20);
    

    基本上它设置页面大小以获取所有内容,然后将其设置回来。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      相关资源
      最近更新 更多