Uncaught ReferenceError: table is not defined
Uncaught ReferenceError: table is not defined
greggreggreg
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>
This discussion has been closed.
Answers
You have
table.rows( {selected: true} ).indexes()
on line 29. You have thisvar my_table= $('#my_table').DataTable(....
) on 21. You don't have a variabletable
anywhere in your code resulting in theUncaught ReferenceError: table is not defined
error. Line 19 should look like thismy_table.rows( {selected: true} ).indexes()
.Kevin
champion, thanks for the fast response.