0

I need to create a custom PDF printout from a specific data table.

I think that with the Ajax button I could do it, but it only sends information in the table from the first page, in this case 20 rows.

I know I can make the table show "all records" on screen and then click the button, but I don't really like this, since all data will be available on screen (thousands of rows).

Is there any other way to send all data?

Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
jaclerigo
  • 557
  • 2
  • 6
  • 31

1 Answers1

-1

I did not found any way to do it with the Ajax button, but found another way. I've used intead:

                "oTableTools": {
                "sSwfPath": "<?=LOC_JQUERY?>swf/copy_csv_xls_pdf.swf?<?=rand()?>",
                "aButtons": [
                    {
                        "sExtends": "download",
                        "sButtonText": "Listagens PDF",
                        "sUrl": "<?=CAMINHO?>_exporta.php",
                        "sAction": "text",
                        "sTag": "default",
                        "sFieldBoundary": "",
                        "sFieldSeperator": "\t",
                        "sNewLine": "<br>",
                        "sToolTip": "Listagens",
                        "sButtonClass": "DTTT_button_text",
                        "sButtonClassHover": "DTTT_button_text_hover",
                        "mColumns": "all",
                        "bHeader": true,
                        "bFooter": true,
                        "sDiv": "",
                        "fnMouseover": null,
                        "fnMouseout": null,
                        "fnClick": function( nButton, oConfig ) {
                            var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
                            var aoPost = [

                                { "name": "cobranca", "value": $("select#cobranca option:selected").val() },
                                { "name": "activo", "value": $("select#activo option:selected").val() },
                                { "name": "id_empresa", "value": $("select#id_empresa option:selected").val() },

                                { "name": "socio_numero", "value": $("#socio_numero").val() },
                                { "name": "socio_nome", "value": $("#socio_nome").val() },
                                { "name": "data1", "value": $("#data1").val() },
                                { "name": "data2", "value": $("#data2").val() },
                                { "name": "idade1", "value": $("#idade1").val() },
                                { "name": "idade2", "value": $("#idade2").val() },
                                { "name": "empresa_profissao", "value": $("#empresa_profissao").val() },

                            ];
                            var aoGet = [];

                            /* Create an IFrame to do the request */
                            nIFrame = document.createElement('iframe');
                            nIFrame.setAttribute( 'id', 'RemotingIFrame' );
                            nIFrame.style.border='0px';
                            nIFrame.style.width='0px';
                            nIFrame.style.height='0px';

                            document.body.appendChild( nIFrame );
                            var nContentWindow = nIFrame.contentWindow;
                            nContentWindow.document.open();
                            nContentWindow.document.close();

                            var nForm = nContentWindow.document.createElement( 'form' );
                            nForm.setAttribute( 'method', 'post' );

                            /* Add POST data */
                            for ( var i=0 ; i<aoPost.length ; i++ )
                            {
                                nInput = nContentWindow.document.createElement( 'input' );
                                nInput.setAttribute( 'name', aoPost[i].name );
                                nInput.setAttribute( 'type', 'text' );
                                nInput.value = aoPost[i].value;

                                nForm.appendChild( nInput );
                            }

                            /* Add GET data to the URL */
                            var sUrlAddition = '';
                            for ( var i=0 ; i<aoGet.length ; i++ )
                            {
                                sUrlAddition += aoGet[i].name+'='+aoGet[i].value+'&';
                            }

                            nForm.setAttribute( 'action', oConfig.sUrl );

                            /* Add the form and the iframe */
                            nContentWindow.document.body.appendChild( nForm );

                            /* Send the request */
                            nForm.submit();
                        },
                        "fnSelect": null,
                        "fnComplete": null,
                        "fnInit": null

                    },                  
                ]
            }

Hope this helps anyone in need also.

jaclerigo
  • 557
  • 2
  • 6
  • 31