Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"oCol is Undefined" Using Datatables and jQuery Ui Dialog

I have a form, for search a registry. This form, shows the info in a jQuery Dialog, and, inside of the dialog, i am using Datatables (Yes, inside of the dialog i have an entire table). I am generating the TR's and TD's dynamically with PHP, and then, PHP paste the string in the HTML. But, when the dialog is shown i get this error:

oCol is undefined: oCol.fnSetData( oData, val );

I'm trying it in Firefox and Chrome and it's the same thing. Also i've searched in http://www.datatables.net, and i discarded a 'malformed table'. I've no idea of what i'm doing wrong.

Can you Help me with this issue?

This is my JS Block:

        <script type="text/javascript" language="javascript" src="lib/jQuery/jquery-1.6.1.js"></script>
        <script type="text/javascript" language="javascript" src="lib/jQuery Ui/js/jquery-ui-1.8.13.custom.min.js"></script>
        <script type="text/javascript" language="javascript" src="lib/Datatables/DataTables-1.8.0/media/js/jquery.dataTables.js"></script>
        <script type="text/javascript">
            $(document).ready(function (){
                $("#results").dialog({
                    title: "Results",
                    width: 900, 
                    height: 500,
                    open: function(event, ui){
                        $("#tRes").dataTable({
                            "bPaginate": true,
                            "bLengthChange": true,
                            "bFilter": true,
                            "bSort": true,
                            "bInfo": true,
                            "bAutoWidth": true
                        });
                    }
                });
            });
        </script>

This is my Table (With the PHP Snippet):

<div id="results">
    <table id="tRes">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>State</th>
                <th>Address</th>
            </tr>
        </thead>
        <tbody>
            <?php 
                echo $rows;
            ?>
        </tbody>
    </table>
</div>

Thanks in Advance.

like image 452
Alejandro Echeverri Avatar asked Jun 19 '11 22:06

Alejandro Echeverri


1 Answers

This may be happening because your table is not structured correctly. Make sure to have thead and tbody. I had this error, and once I added the thead and tbody it was gone. My settings were nothing like the settings in the other reply - I'm not sure why that one worked, as it didn't for me.

table
  thead
    tr
      th`s
  tbody
    tr`s
      td`s
like image 97
thugsb Avatar answered Sep 19 '22 13:09

thugsb