Search code examples
angularjsprintingkendo-gridexport-to-excelalasql

How to Print and export kendo-grid data in angular js?


i am trying to add two functions to my project. One is to export the grid data as its views to an excel (i am using kendo-grid and the grid data has been formatted from the UI side) and the second one is to print the grid data with the grid lines. i have added both, but i am having two problems. 1. Exporting to excel with the numbers formatted. i used this example http://jsfiddle.net/agershun/00nfeq12/

alasql('SELECT x [No.],Type,Amount INTO XLSX("Type.xlsx",{headers:true}) FROM ?',[  $scope.data.Data]);      

    };

$scope.data.Data is a result of the api. So it contains the actual data. But in my grid, i have added custom formatting.

  1. printing with the grid lines. I am using this example. Print a div using javascript in angularJS single page application

but the print just shows the data, no border lines and these are needed.

How do i solve this please? thanks


Solution

  • How to export to Excel and keep custom formatting?

    You can write your own formatting function, for example round number to 2 digits:

    alasql.fn.myfmt = function(n) {
         return Number(n).toFixed(2);
    }
    
    alasql('SELECT name, myfmt(amt) INTO XLSX("john.xlsx",{headers:true}) \
          FROM ?',[$scope.items]);
    

    See the example at jsFiddle

    How to print Kendo UI grid?

    You can read and try the example how to print fron Kendo UI grid in this article.