Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom header or title and footer information of company in csv export option of datatable?

I am using dataTables and trying to add new feature where I can add customized title information or can say customize header and footer information.

So what I am trying to do is to add customize company information into CSV file when someone press CSV button on datatables options of export table information.

like here: https://datatables.net/extensions/buttons/examples/initialisation/export.html

and what I am keen to use is following option "customize" define by datatables here: https://datatables.net/reference/button/csv

So as in above link one of the option of CSV is called customize - where I can achieve to add customize information in CSV file but I don't know how I can use this customize option. So if someone give me jsfiddle example or some hint would be really helpful guys.:)

Apart from my question I did some research and found following which is useful but don't know in excel and csv what can be used:

dom: 'Bftripl',
    buttons: [
        'excelHtml5',
        //'csvHtml5',
        //'pdfHtml5',
        {
            extend: 'pdfHtml5',
            customize: function (doc) {
                doc.content.splice(1, 0, {
                    margin: [0, 0, 0, 12],
                    alignment: 'center',
                    image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACsAAAAuCAYAAACxkOBzAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG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PNcngYNfoaKdDej34KA5e2oWadYyWWa5IiX0w6FHkLaGm5FxoaGqC6upqdvnBiBrLaBdh+G+12e1NlZWUtkvamXoPUBARGxS2//kfd3NE4/zWel8EpFIPXWq6TRc492CSab13e0x/oew+Gr+0DQXSMsQydLElzbjvS9EGGRJoML+TtgcvwakruwYmMnzVrVi0uZtbSpS0L8d1sUW1tbZ3TBhV7Dw8/d/D8kmfwVadYU6JQbK0Cl90Fw33vPzF4ceuLwf63dOsj2sxavPnImohzzE+k7DuqvgCMpIbvZ6oxN5AxcsqUqT6XyzEL5RZ761Nfhc23ZKPoqZtrEb3TSu0Tu64cWdIYvHkiKNocZArO+ftrIWS5LOBNx2NerokMMCMyLhD9VBNtoiZzFo8q2CsqrGXNDaJgl0Jdfz2JFiBSoplQMFmeISXQzyLdC8w1Pgv5tMTo0DD8mizhQBsnJ3jRgfbPKbQxKPRHaWOfRlrME02DnEh/T7DQ13bjWMxCPhPZ5JdzPMrEiqOXFc0NiHUQSBlgXFONxYp5oipQUnYKkgYH/WylMEgLFFyWmcOIlArpJBO07ZJfxKMM4uOJLM8QJW+rHgYuE2kLE2FWEqwEVCbFCiVpEB2lP92HKHhmgSk5iAVIwEYjWkR9tYQh7KTXrUx0M5HNFFWDKIliGBFkgqcwcjD0y4l5qt8gbKWkCEE3/bXPQ8naGT2LGYpNY8gqDJEETb2NLlKj56KmxadqQCzAtsBU8SwEZi9kiKxBlmMKxYi0+f68jpKPrGqKRJTqS2Sux5lImHWrFSCDUSqDURrphCn9Wi6yWoZCiFLhcwzBCFNgtiyRLcQJjP+LRZh/9hmkFabIspI10icxX6zRL4lR4naT7wo5vFbLEATJRDjKuIJhXQX5LBsFYD7HacqsGYpKMBdEDp9VmGeypA1pJJjGoObzWc2kF5XRmZCloAprt+mey0Zaod9hbrt5mwIwRNk/lE22xmcZcnI9T8tCXMswD6QNM/8XYABHXZABxc4pngAAAABJRU5ErkJggg=='
                });
            }
        },

From here: how to customize export to csv,excel,pdf in jquery datatables

I have asked this question here as well: https://datatables.net/forums/discussion/38275/how-to-use-csv-customize-option-in-dattable-export-csv-button?new=1

but still no idea for csv???

like image 369
Jimil Avatar asked Oct 12 '16 00:10

Jimil


1 Answers

I hope some will come up with something but nothing come up. However, as I found lot of people looked at though.

Anyways, I have found answer for csv but still didn't find anything for excel. So will make another question for it but for CSV answer is as follows:

{
            extend: 'csvHtml5',
              customize: function (csv) {
                 return "My header here....\n\n"+  csv +"\n\nMy Footer here.....";
              }
        }

Thanks to allan - datatable expert and get back to me without arguing that whether I have seen any csv with header and footer. So thanks to allan and you can see original answer here: https://datatables.net/forums/discussion/38275

Thanks and have a look:)

like image 142
Jimil Avatar answered Sep 27 '22 18:09

Jimil