nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.36k stars 1.08k forks source link

export pivot customized config and data to json #713

Open frankernesto87 opened 7 years ago

frankernesto87 commented 7 years ago

Hi, and thank you for developing this usefull tool. I 've been reading and I know there are ways to save the state of a customized pivot state, but I'm needing also to keep the data in a json or a xml , so I can export it later to excel or pdf files. Right now I'm only able to save the configuration, but not the data, Am I missing something???, best regards

nicolaskruchten commented 7 years ago

There's no programmatic way to access the output of the pivot table... There is the TSV exporter, however: http://nicolas.kruchten.com/pivottable/examples/mps_export.html

nithishanf commented 7 years ago

Hi @frankernesto87 , I tried Export to excel and it is working even for large data. If this is something you asked for then please find below.

<script>
    $("#btnExportPivot").on('click', function (e) {
        e.preventDefault();
        var data = $('.pvtRendererArea>table').html();

        $.ajax({
                type: 'POST',
                url: 'yourURL1',
                data: { data: data },
                success: function (result) {
                    window.location = 'yourURL2';
                    e.preventDefault();
                },
                error: function (xhr, textstatus, errorThrown) {
                    alert("An error has occured! Kindly contact administrator.");
                    e.preventDefault();
                }
            })
        })
</script>

I used this js for my MVC application. So the code is: Controller

[HttpPost]
        [ValidateInput(false)]
        public ActionResult yourURL1(string data)
        {

            TempData["ExportPivotResult"] = data;
            return null;
        }
        public ActionResult yourURL2()
        {
            yourModel objVM = new yourModel();
            objVM.pivotData = Convert.ToString(TempData["ExportPivotResult"]);
            Response.AddHeader("content-disposition", "attachment; filename=PivotSheet.xls");
            Response.ContentType = "application/ms-excel";
            return PartialView(objVM);
        }

View

@model yourModel()
<table id="pivot">
    @Html.Raw(Model.pivotData)
</table>
frankernesto87 commented 7 years ago

Hi Nicolas finally I've managed to export to excell and very hardly way to pdf, anyway your help has been very usefull, now I have another question. Is it possible to remove sorting of pivot table?? It alows alphabethical and it's reverse by 'keys_a_to_z, value_a_to_z......' but I'm looking for showing the data as it comes from a certain source. I also managed to paginate the pivot , and it shows the data ok in each page, but my way to export excell is with all the data, so the pivot applies the alphabethical order and the result is quite different. Any tips?? Thanks a lot, Regards Frank

2017-06-15 2:57 GMT-05:00, nithishanf notifications@github.com:

Hi @frankernesto87 , I tried Export to excel and it is working even for large data. If this is something you asked for then please find below.

I used this js for my MVC application. So the code is: Controller

`[HttpPost] [ValidateInput(false)] public ActionResult yourURL1(string data) {

        TempData["ExportPivotResult"] = data;
        return null;
    }
    public ActionResult yourURL1()
    {
        yourModel objVM = new yourModel();
        objVM.pivotData =

Convert.ToString(TempData["ExportPivotResult"]); Response.AddHeader("content-disposition", "attachment; filename=PivotSheet.xls"); Response.ContentType = "application/ms-excel"; return PartialView(objVM); }` View

`@model yourModel()

@Html.Raw(Model.pivotData)
` -- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/nicolaskruchten/pivottable/issues/713#issuecomment-308657914
MeriemBH commented 5 years ago

Hello nithishanf , i noticed that you succeeded in exporting the result of pivottable to excel file. Can you please tell me in which files you added your coding (MVC) explained above. thanks