We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12120
    • 4 Posts
    I use the jquery plug-in dataTables to format tables to display a range of products. dataTables offers a lot of options to format a table and I’m having a problem with one of them. Here is the code of the call I have in the template
    <script type="text/javascript">
    $(document).ready(function() {
    	$("#sqlQueryResultTable").dataTable({
    		"aoData": [
    				null,
    				null,
    				null,
    				null,
    				null,
    				null,
    				null,
    				null,
    				{"bSortable": false, "bSearchable": false},
    				{"bSortable": false, "bSearchable": false}
    				],
    		"sPaginationType": "full_numbers",
    		"oLanguage": {"sUrl": "[(base_url)]assets/templates/kniel_mf54/js/dataTables-1.5/media/language/en_UK.txt"},
    		"aaSorting": [[1, "desc"]]
    	} );
    } );
    </script>
    

    This is pretty straight forward and works in a static page. The last parameter aaSorting however causes the trouble if MODx caomes into play. The problem is, the parameters for aaSorting are given as an array surrounded by a pair of brackets for the array and another pair of brackets for each pair of parameters (see the documentation here). Since MODx uses double brackets for the inclusion of snippets, this does not work. The codes gets parsed and the content between the parameters gets thrown away by MODx. When the page loads, I get a JavaScript syntax error.

    Is there a way to escape the double brackets so I can hand over the parameters and not let MODx interpret this as a snippet?
      • 7231
      • 4,205 Posts
      The quick solution would be to put the javascript in an external file (you would not be able to use the [(base_url)] though).
      <script language="JavaScript" type="text/javascript" src="assets/js/file-to-load.js"></script>

      You can try simply adding while space between the brackets "[ [" I think that JavaScript will ignore the spaces.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 12120
        • 4 Posts
        Quote from: dev_cw at Mar 17, 2009, 07:41 AM

        You can try simply adding while space between the brackets "[ [" I think that JavaScript will ignore the spaces.
        Thanks dev_cw,

        I received exacly the same tip from Allan Jardine, the programmer of dataTables and implemented it. The table is now working as I wished.

        Hans
          • 7231
          • 4,205 Posts
          That is good to know, I was only guessing rolleyes
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]