如何将jquery数据表属性移动到函数

时间:2018-08-01 07:13:33

标签: jquery datatables

这里我使用jQuery Datatable,pdfmake插件。我尝试创建pdf报告。

$('#example').DataTable( {

    responsive : true,
    "scrollX" : true,
    "scrollCollapse" : true,
    dom: 'Bfrtip',
    buttons: [//from here ---------------------------------
        {

            extend: 'pdfHtml5',
            orientation: 'landscape',
            pageSize: 'A4',
            title: 'Transaction Inquiry Report',
            filename: 'transaction_inquiry_report',

            customize: function (doc) {

                var now = new Date();
                var jsDate = now.getDate()+'-'+(now.getMonth()+1)+'-'+now.getFullYear();

                var logo = 'data:'+baseURL+'resources/images/report/car_logo.jpg';

                doc.pageMargins = [20,70,10,30];

                doc.defaultStyle.fontSize = 10;
                doc.styles.title = {
                          alignment: 'center',
                          fontSize: 25,
                          margin: 0
                        }

                doc.styles.tableHeader.fontSize = 10;
                doc.content[1].table.widths =
                    Array(doc.content[1].table.body[0].length + 1).join('*').split('');
                doc.content[2] = {text: 'Total Amount   : ', margin:[0, 20] }; //'Total Amount  : ';
                doc.content[3] = {text: '....................\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t....................'};
                doc.content[4] = {text: 'Checked By\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSignature'};





                doc['header']=(function() {
                    return {
                        columns: [
                            {
                                image: logo,
                                width: 130
                            },
                            [
                                    {
                                        alignment: 'right',
                                        text: 'User Name    :   '+login_user,
                                        fontSize: 10,
                                    },
                                    {
                                        alignment: 'right',
                                        text: 'Operatiopn code  :   '+opr,
                                        fontSize: 10,
                                    },
                                    {
                                        alignment: 'right',
                                        text: 'Location :   '+loc,
                                        fontSize: 10,
                                    },
                                    {
                                        alignment: 'right',
                                        text: 'Report Date  :   '+ new Date().toISOString().slice(0,10),
                                        fontSize: 10,
                                    }

                            ]
                        ],
                        margin: 20
                    }
                });

                doc['footer']=(function(page, pages) {
                    return {
                        columns: [
                            {
                                alignment: 'left',
                                text: ['Created on: ', { text: jsDate.toString() }],
                                fontSize: 7,
                            },
                            {
                                alignment: 'right',
                                text: ['page ', { text: page.toString() },  ' of ', { text: pages.toString() }],
                                fontSize: 7,
                            }
                        ],
                        margin: [20, 0]
                    }
                });

                var objLayout = {};
                objLayout['hLineWidth'] = function(i) { return .5; };
                objLayout['vLineWidth'] = function(i) { return .5; };
                objLayout['hLineColor'] = function(i) { return '#aaa'; };
                objLayout['vLineColor'] = function(i) { return '#aaa'; };
                objLayout['paddingLeft'] = function(i) { return 4; };
                objLayout['paddingRight'] = function(i) { return 4; };
                doc.content[0].layout = objLayout;

            }
        }
    ],//to here-----------------------------

        "ajax": {
            "url": baseURL+"/tran-insert-data/"+url,
            "type": "POST",
                "data": {
                    "fromDate":fromDate,
                    "toDate":toDate,
                    "transtatus":stanStatus,
                    "tranType":tranType,
                    "exchCode":exchID,
                    "batchType":batchName
                }
        },

    "columns": [

        { "data": "tnAgntRefNo" },
        { "data": "inpdate" },
        { "data": "tnAmount" },
        { "data": "accNo" },
        { "data": "bnkCode" },
        { "data": "brCode" },
        { "data": "statusname" },
        { "data": "beneficieryName" },
        { "data": "senderName" },
        { "data": "errDescription" }
    ]

} );

我需要将按钮属性内的代码块(从此处//移到此处)到另一个函数,因为我必须创建多个报告。任何人都知道任何可行的方法吗?但是这些东西无济于事。如果没有办法,我必须在每个报告中使用整个代码。那么有人可以帮助吗?

0 个答案:

没有答案