Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81938

Data Tables Custom View then export to csv - problem

$
0
0

Hello and thanks for interesting in my problem.

I've got implemented database with datatables for equipment in company.

The problem is when I export my data to csv. Always every row is included into the csv file(I open it with excel), even when i custom view only a few of columns.

$( "#custom_print_view" ).dialog({
                   autoOpen: true,
                   modal: true,
                   height:400,
                   width:350,
                    buttons: {
                    "Show": function() {

                            $("#empty").dialog("close");
                            toShow.elements.push("inTime");
                            toShow.data = $("#custom_print_date").val();
                        if(toShow.elements.length >= 1){
                            $.post( baseUrl+"CustomPrint/download",{toShow: JSON.stringify(toShow)}).done(function(data){
                            data = JSON.parse(data);
                            columns = elementsToTable(toShow.elements);
                            update(data,columns);
                            //data = JSON.parse(data);

                            $('#exportLink').css('display', 'inline-block'); //show button when ready
                            var filename = 'hardware.csv'; //export .csv file
                            var blobby = new Blob([makeCSV(data)], {type: 'text/csv;charset=utf-8'}); //make blob object

                                    $(exportLink).attr({
                                                'download' : filename,
                                                'href': window.URL.createObjectURL(blobby),
                                                'target': '_blank'
                                                });

                            })
                    }
                    else{
                            $("#empty").dialog("open");

                        }

                            $(this).dialog("close");
                        }
                    }
            });

        function update(data,columns){
                    var result='';
                    table = $('#Date').DataTable({

                    "pagingType": "simple",
                    "lengthMenu": [[50, 100, 150,200, -1], [50, 100, 150,200, "All"]],
                    "data": data,
                    "destroy": true,
                    "order": [[ 1, "asc" ]],
                    "scrollY": ($(window).innerHeight()-300)+"px",
                    "scrollCollapse": true,
                    "paging":         true,
                      "columns": columns,
                      "columnDefs": [ {


                            "targets": 0,

                            "render": function ( data, type, full, meta ) {
                                if(data!=null)
                                    {
                                       return data.replace('"',"'");
                                    }
                                else{
                                    return data;
                                    }

                            }
                          } ]

                    })

        }

Where is the problem? I found on examples that it can work, and export only things that i searched through the search box or only the custom view with defined columns.

Please help me or ask me to copy other lines of code.

Cheers


Viewing all articles
Browse latest Browse all 81938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>