[web2py] call web2py in view from a jQuery script

109 views
Skip to first unread message

Richard

unread,
Aug 4, 2011, 5:36:13 PM8/4/11
to web2py-users
Hello,

I try to do this :

$(document).ready(function() {
$('table.sortable').dataTable( {
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "{{=URL('static','plugin_added/DataTables-1.8.1/extras/
TableTools/media/swf/copy_cvs_xls_pdf.swf')}}"
},
} );
} );

Seems the same problem that Vineet report here :
http://stackoverflow.com/questions/6476133/json-data-for-jquery-datatable-in-web2py

Is it possible??

Thanks

Richard


Richard Vézina

unread,
Aug 4, 2011, 5:44:10 PM8/4/11
to web2py-users
I get it like this : var sSwfPath_location = "{{=URL('static','plugin_added/DataTables-1.8.1/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf')}}"

And replace :

 "sSwfPath": "{{=URL('static','plugin_added/DataTables-1.8.1/extras/
TableTools/media/swf/copy_cvs_xls_pdf.swf')}}"

With 

 "sSwfPath": sSwfPath_location

@ Vineet : It could work maybe for your issue...

Richard

Anthony

unread,
Aug 4, 2011, 5:56:33 PM8/4/11
to web...@googlegroups.com
On Thursday, August 4, 2011 5:36:13 PM UTC-4, Richard wrote:
Hello,

I try to do this :

$(document).ready(function() {
$('table.sortable').dataTable( {
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "{{=URL('static','plugin_added/DataTables-1.8.1/extras/
TableTools/media/swf/copy_cvs_xls_pdf.swf')}}"
 
Is the line break after "extras/" in your original code? If so, that should be causing a syntax error in the web2py view rendering. If you remove that line break, web2py should fill in the URL properly. If it still doesn't work, it probably has something to do with not setting up DataTables properly.
 
Anthony
 

Richard

unread,
Aug 4, 2011, 5:58:49 PM8/4/11
to web2py-users
No, I think it a Datatables parsing issue since Datatables TableTools
is waiting for a URL... I don't know why...

Richard

Anthony

unread,
Aug 4, 2011, 6:24:14 PM8/4/11
to web...@googlegroups.com
Can you show more of your code? I don't see why your second version should work if the first one didn't. Was the original code inside a web2py view (so the URL would get rendered before the HTML was sent to the browser)?
 
Anthony

On Thursday, August 4, 2011 5:58:49 PM UTC-4, Richard wrote:
No, I think it a Datatables parsing issue since Datatables TableTools
is waiting for a URL... I don't know why...

Richard

Richard Vézina

unread,
Aug 5, 2011, 9:43:54 AM8/5/11
to web...@googlegroups.com
All is in the view :

{{extend 'layout.html'}}

{{=table}}

all needed dependency

$(document).ready(function() {
    $("#tabs").tabs( {
        "show": function(event, ui) {
            var oTable = $('div.dataTables_scrollBody>table.sortable', ui.panel).dataTable();
            if ( oTable.length > 0 ) {
                new FixedColumns( oTable, {
                    "iLeftColumns": 1,
                } );
            }
        }
    } );
    
    var sSwfPath_location = "{{=URL('static','plugin_added/DataTables-1.8.1/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf')}}"
    $('table.sortable').dataTable( {
        "bJQueryUI": true,
        "bAutoWidth": false,
        "bScrollInfinite": true,
        "sScrollY": "300px",
        "sScrollX": "100%",
        "bPaginate": false,
        "bProcessing": true,
        "bSortClasses" : false,
        "sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
   "aButtons": [
                "copy",
                "csv",
                "xls",
                {
    "sExtends": "pdf",
                    "sPdfOrientation": "landscape",
                    "sPdfMessage": "Your custom message would go here."
                }
            ],
    //"sRowSelect": "multi", // It copy all rows anyway?? + Glitch if fixedcolumn
"sSwfPath": sSwfPath_location
},
        "oLanguage": {
            "sSearch": "Search:"
         },
        "aoColumnDefs": [
            { "sWidth": "10%", "aTargets": [ -1 ] }
        ]
    } );
    
} );
</script>


I think the HMTL is already loaded... I think as I said that it coming from the Datatable parsing and the {} that have a meanig in javascript...

I let you understand what for it works that way and not the other ;-)

Richard
Reply all
Reply to author
Forward
0 new messages