<commit_before>require.config({paths: {
    'jspdf': '../extensions/TablePDFexport/jspdf_lib/jspdf.debug',
    'jspdf-autotable': '../extensions/TablePDFexport/jspdf_lib/jspdf.plugin.autotable'
}});

define(
    [
        "jquery",
        "jspdf",
        "jspdf-autotable"
    ],

function( jquery, jsPDF, html2canvas, autotable ){


    function getColumns(data) {
        return data[0].map(function(a, pos){
            return "Header "+pos;
        });
    }
    var autoTableFromData = function ( data ) {
        var doc = new jsPDF();
        doc.autoTable(getColumns(data), data, {
            overflow: 'linebreak',
            columnWidth: 'wrap',
            styles: {cellPadding: 0.5, fontSize: 8}
        });
        doc.output('dataurlnewwindow');
    };

    return {

        do:  function( elSelector, scope ){

            var requestPage = [{
                qTop: 0,
                qLeft: 0,
                qWidth: 10, //should be # of columns (it can be worked out from API)
                qHeight: 100 //number of rows to fetch
            }];

            scope.object.backendApi.getData( requestPage )
                .then( function ( dataPage ) {
                    var data =  dataPage[0].qMatrix.map( function(row) {
                        var r = [];
                        row.forEach(function(cell) {
                            r.push(cell.qText);
                        });
                        return r;
                    });
                    autoTableFromData(data);

                } );
        }
    }

});<commit_msg>Fetches all data till the end<commit_after>require.config({paths: {
    'jspdf': '../extensions/TablePDFexport/jspdf_lib/jspdf.debug',
    'jspdf-autotable': '../extensions/TablePDFexport/jspdf_lib/jspdf.plugin.autotable'
}});

define(
    [
        "jquery",
        "jspdf",
        "jspdf-autotable"
    ],

function( jquery, jsPDF, html2canvas, autotable ){


    var autoTableFromData = function ( headers, data ) {
        var doc = new jsPDF();
        doc.autoTable(headers, data, {
            columnWidth: 'wrap',
            styles: {
                cellPadding: 0.5,
                fontSize: 8,
                overflow: 'linebreak'
            }
        });
        doc.save("output.pdf");
        //doc.output('dataurlnewwindow');

    };

    var getPageData = function(scope, requestPage ) {
        return scope.object.backendApi.getData( requestPage )
            .then( function ( data ) {
                return pageData = data[0].qMatrix.map( function(row) {
                    var r = [];
                    row.forEach(function(cell) {
                        r.push(cell.qText);
                    });
                    return r;
                });
            } );
    };

    var totalData;

    function fetchAllDataPages( scope, arrayOfPages ) {
        totalData = [];
        return arrayOfPages.reduce(function(promise, page) {
            return promise.then( function(total) {
                return getPageData(scope, page).then(function(data) {
                    return total.concat(data);
                });
            });
        }, Promise.resolve(totalData));
    }


    return {

        do:  function( elSelector, scope ){

            //Headers
            var dimensions = scope.object.layout.qHyperCube.qDimensionInfo,
                measures = scope.object.layout.qHyperCube.qMeasureInfo;

            var headers = [];
            dimensions.forEach(function(d){
                headers.push(d.qFallbackTitle);
            });
            measures.forEach(function(m){
                headers.push(m.qFallbackTitle);
            });
            //----


            //Data
            var count = 500,
                numpages = Math.ceil(scope.object.backendApi.getRowCount()/count),
                arrayOfPages = [];

            for ( var i=0; i<numpages; i++){
                var pageRequest = [{
                    qTop: i*count,
                    qLeft: 0,
                    qWidth: scope.object.layout.qHyperCube.qSize.qcx, //should be # of columns (it can be worked out from API)
                    qHeight: count //number of rows to fetch
                }]
                arrayOfPages.push(pageRequest);
            }

            fetchAllDataPages(scope, arrayOfPages).then(function( res ) {
                autoTableFromData(headers, res);
            });
            //-----
        }
    }

});
{'fraction_non_alphanumeric': 0.12112359550561798, 'fraction_numerical': 0.005168539325842696, 'mean_word_length': 1.3827623126338329, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6087350', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1189, 'n_words': 230}