Cannot Commit Changes
Cannot Commit Changes
kennemore
Posts: 2Questions: 1Answers: 0
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!
This discussion has been closed.
Answers
I noticed you have
idSrc: 'schedules.idschedules',
in your parent Datatables config.That is not a Datatables option but it an Editor option. I think you want to use
rowId
instead. Not saying that is the issue though.I don't see anything from scanning the config that stands out as an issue. Have you looked at the Browser's Dev Tools to see if an ajax request is sent when updating the child table?
Kevin
Yeah, I added that to the table out of desperation but it ignored it either way. Thanks for looking at this. I found it. In the blog example it has an
Since my editor was not posing such a value no action was taken on the server side. I wasn't quite sure how to add that to editor. I am sure there is a much better way but I got it to work by adding an nested if that creates an editor instance without the
->where( 'schedtimes.idsched', $_POST[ 'idsched' ] )
Thanks again!
Thanks for posting back - great to hear that you've got it working now!
Allan