rowReorder not submitting ajax for reorder
rowReorder not submitting ajax for reorder
drewturk
Posts: 27Questions: 8Answers: 0
HI,
here is my editor implementation of rowReorder:
var editor = new $.fn.dataTable.Editor({
ajax: '/client/information/updatecontacts',
table: '#contacts',
idSrc: 'id',
fields: [
{
name: "position",
type: "hidden"
},
{
label: "Name",
name: "name",
labelInfo: "Required"
},
{
label: "Title",
name: "title"
}
]
}).on('postCreate postRemove', function() {
console.log('postCreate postRemove');
datatable.ajax.reload(null, false);
}).on('initCreate', function() {
console.log('initCreate');
editor.field('position').enable();
}).on('initEdit', function() {
console.log('initEdit');
editor.field('position').disable();
});
here is my datatable implementation:
var datatable = $("#contacts").DataTable({
ajax: '/client/information/getcontacts',
responsive: true,
order: [[0,'asc']],
rowReorder: {
selector: 'td:not(:first-child, :last-child)',
dataSrc: 'position',
editor: editor
},
columns: [
//0
{
data: "position",
visible: true,
colvis: false,
//className: 'never',
render: function(data) {
return parseInt(data)+1;
}
},
//1
{
title: "Name",
name: "name",
data: "name",
searchable: false
},
//2
{
title: "Title",
name: "title",
data: "title",
searchable: false
},
],
columnDefs: [
{
className: 'reorder',
targets: [1,2,3,4,5,6,7,8]
}
]
});
I want to utilize the editor for updating the rows after a reorder, but the editor is never called via AJAX. I can reorder just fine in UI, but the AJAX does not work and therefore I can't 'save' the changes. Thanks.
p.s. using DataTables v 1.10.12 and RowReorder v1.1.2
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi dataTables staff,
We discovered a bug with
idSrc: 'id'
option when used with rowReorder extension. We can not use id's other than the defaultDT_RowId
. This does however work with all of our other datatables, just not when the rowRerorder extension is used.we are temporarily resolving the issue by replacing id with DT_RowId:
Hi,
Thanks for your messages. The
idSrc
option is only used for Editor, it isn't a property that DataTables itself, or RowReorder has access to. Instead, the property to use is DataTables'rowId
property. By default that isDT_RowId
which is why it works when using your workaround above, but if you just have anid
property you want to use, addrowId: 'id'
into your DataTables initialisation.Regards,
Allan
Thank you so much Allan.
One more thing...when I am trying to persist my row order changes in a database, I am missing other fields which are necessary for the record. What I mean is that rowReorder only posts the data as such:
Therefore other data fields are not available for the update. My idea around this is to request the particular record when editing the order sequence (as you can see in my
edit()
method below) and then use this to build (applyFormData($object)
) my object for updating. Does that make sense? How would you suggest this normally be handled?Additionally, I have problems with the validator giving errors on a reorder because the
name
field is not present onlyposition
. My work around for that is checking the action for non-edit which works for row reorder, but this won't work for actual form editing. What are your suggestions there?Thanks.
This is caused by the
submit
option of theform-options
object. RowReorder is setting that option to bechanged
so only the changed values are submitted.That's actually hard coded into RowReorder at the moment so you need to modify the source to change it. It would need to be changed to be
allIfChanged
to submit all of the data.Regards,
Allan
Allan, just to let you know, I also need to set the option to 'allIfChanged', because my reordering has to trigger also a reorder in another table and therefore I need some more data from the reordered set than just the sequence.
So it would be great if you could implement this to the next release!
I've committed the required change here. The documentation included in the commit includes an example, but basically you just need to add:
to your
rowReorder
object.The nightly version will be up-to-date with that change in a few minutes. Not yet sure when the next RowReorder release will be.
Regards,
Allan