I followed the blog post about parent child tables and I am able to get the two tables to reflect each other however when I make changes to the child table no errors are thrown and no changes committed.
$( document ).ready( function () {
var schedEditor = new $.fn.dataTable.Editor( {
ajax: "rest/getScheds2.php",
table: "#schedTable",
idSrc: 'schedules.idschedules',
fields: [ {
label: "id:",
name: "schedules.idschedules"
},{
label: "Name:",
name: "schedules.schedname"
},{
label: "From:",
name: "schedules.seasonfrom"
},{
label: "To:",
name: "schedules.seasonto"
} ]
} );
var schedTable = $( '#schedules' ).DataTable( {
dom: "Bfrtip",
ajax: "rest/getScheds2.php",
idSrc: 'schedules.idschedules',
columns: [ {
data: 'schedules.idschedules'
}, {
data: 'schedules.schedname'
},{
data: 'schedules.seasonfrom'
} ,{
data: 'schedules.seasonto'
}],
select: {
style: 'single'
},
buttons: [ {
extend: "create",
editor: schedEditor
}, {
extend: "edit",
editor: schedEditor
}, {
extend: "remove",
editor: schedEditor
} ]
} );
var timesEditor = new $.fn.dataTable.Editor( {
ajax: {
url: 'rest/getTimes.php',
data: function ( d ) {
var selected = schedTable.row( {
selected: true
} );
if ( selected.any() ) {
d.idsched = selected.data().id;
}
}
},
table: '#times',
fields: [ {
label: "Day:",
name: "schedtimes.dayofweek"
}, {
label: "From:",
name: "schedtimes.fromtime"
}, {
label: "To:",
name: "schedtimes.totime"
},{
label: "id:",
name: "schedtimes.idsched"
}
]
} );
var timesTable = $( '#times' ).DataTable( {
dom: 'Bfrtip',
ajax: {
url: 'rest/getTimes.php',
type: 'post',
data: function ( d ) {
var selected = schedTable.row( {
selected: true
} );
if ( selected.any() ) {
//console.dir(selected.data());
//alert(selected.data()['schedules']['idschedules']);
d.idsched = selected.data()['schedules']['idschedules'];
}
}
},
columns: [ {
data: 'schedtimes.dayofweek'
}, {
data: 'schedtimes.fromtime'
}, {
data: 'schedtimes.totime'
}],
select: true,
buttons: [ {
extend: 'create',
editor: timesEditor
}, {
extend: 'edit',
editor: timesEditor
}, {
extend: 'remove',
editor: timesEditor
} ]
} );
schedTable.on( 'select', function () {
timesTable.ajax.reload();
timesEditor
.field( 'schedtimes.idsched' )
.def( schedTable.row( {
selected: true
} ).data().id );
} );
schedTable.on( 'deselect', function () {
timesTable.ajax.reload();
} );
timesEditor.on( 'submitSuccess', function () {
schedTable.ajax.reload();
} );
schedEditor.on( 'submitSuccess', function () {
timesTable.ajax.reload();
} );
} );
</script>
I have also enabled debug mode but when I attempt to update a value no data is sent. I am lost. Any help would be appreciated.
Thanks!