Uncaught ReferenceError: table is not defined

Uncaught ReferenceError: table is not defined

greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

I am trying to Clone a row. But I keep getting a error when I click the Clone button.

Any ideas please?

<table id="my_table" class="display" width="100%" cellspacing="0"></table>

<script>
                            $(document).ready(function() {
                                editor_my_table= new $.fn.dataTable.Editor( {
                                    ajax: 'lookup.php',
                                    table: '#my_table',
                                    fields: [
                                        {
                                            "label" : "Ref",
                                            "name": "my_table_id"
                                        },{
                                            "label" : "My Name",
                                            "name": "my_table_name"
                                        }
                                    ]
                                } );



                                var my_table= $('#my_table').DataTable({
                                    buttons: [
                                        {
                                            extend: "selected",
                                            text: 'Clone',
                                            action: function ( e, dt, node, config ) {
                                                // Start in edit mode, and then change to create
                                                editor_my_table
                                                    .edit( table.rows( {selected: true} ).indexes(), {
                                                        title: 'Clone',
                                                        buttons: 'Clone'
                                                    } )
                                                    .mode( 'create' );
                                            }
                                        },
                                    ],
                                    rowId: 'id',
                                    scrollX: true,
                                    pagingType: "numbers",
                                    processing: true,
                                    serverSide: true,


                                    select: true,
                                    lengthChange: true,
                                    order: [[ 2, "desc" ]],
                                    columns: [
                                        {
                                            "title" : "Ref",
                                            "data": "my_table_id"
                                        },{
                                            "title" : "My Name",
                                            "data": "my_table_name"
                                        }
                                         ],
                                    ajax: {
                                        url: 'lookup.php',
                                        type: 'post'
                                    },

                                } );
                            }  );
                        </script>

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You have table.rows( {selected: true} ).indexes() on line 29. You have this var my_table= $('#my_table').DataTable(....) on 21. You don't have a variable table anywhere in your code resulting in the Uncaught ReferenceError: table is not defined error. Line 19 should look like this my_table.rows( {selected: true} ).indexes().

    Kevin

  • greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

    champion, thanks for the fast response.

This discussion has been closed.