Kendo excel导出 – 如何导出自定义模板列?
我有一个我定义的剑道网格。 我通过data-toolbar='["excel"]'
启用excel导出工具data-toolbar='["excel"]'
问题是这只会导出没有定义模板的字段。 (下面的网格中的前3个:Checkpoint,Location,Patrolled By),其他列显示在Excel文档中,但是这些列的单元格都是空的。
我怎样才能得到的价值出现在Excel导出? 我猜这将需要在Excel导出之前进行一些预处理,因为Excel导出函数不解释我的自定义字段的HTML模板。
<div id="Checkpoints"> <div ... data-toolbar='["excel"]' data-excel='{ "fileName": "CheckpointExceptionExport.xlsx", "allPages": "true" }' ... data-columns='[ { "field": "checkpoint_name", "title": "Checkpoint", "filterable": { "cell": { "operator": "contains"}}}, { "field": "location_name", "title": "Location", "filterable": { "cell": { "operator": "contains"}} }, { "field": "patrolled_by", "title": "Patrolled By", "filterable": { "cell": { "operator": "contains"}} }, { "field": "geotag", "title": "GeoTag", "template": kendo.template($("#geotagTemplate").html()) }, { "field": "geofence", "title": "GeoFence", "template": kendo.template($("#geofenceTemplate").html()) }, { "field": "completed", "title": "Completed", "template": kendo.template($("#completedTemplate").html()) }, { "field": "gps", "title": "GPS", "template": kendo.template($("#gpsTemplate").html()) } ]'> </div> </div>
我遇到了这个处理excel导出事件的代码片段,但是我没有看到以我定义网格的方式使用这个事件处理器的方法。
<script> $("#grid").kendoGrid({ excelExport: function(e) { ... }, }); </script>
检查http://docs.telerik.com/kendo-ui/controls/data-management/grid/excel-export#limitations ,这解释了为什么发生这种情况,并显示如何进行。
网格在Excel导出过程中不使用列模板 – 仅导出数据。 此行为的原因是列模板可能包含任何不能转换为Excel列值的HTML。 有关如何使用不包含HTML的列模板的更多信息,请参阅此列模板示例 。
更新
为了在使用声明性小部件初始化时附加Kendo UI事件处理程序,请使用data-bind
HTML属性和事件绑定 :
<div data-role="grid" data-bind="events: { excelExport: yourExcelExportHandler }"> </div>
检查Kendo UI Grid MVVM演示,以获得类似的例子。
yourExcelExportHandler
应该是yourExcelExportHandler
定义的一个函数,类似于上面的例子中的onSave
。
窗口小部件初始化之后,还可以附加excelExport
事件。