couple of problems with rowReorder
couple of problems with rowReorder
I am using this editor plugin for a few reference tables, but have noticed some strange behaviour.
If i try and delete multiple rows, the order number creates duplicates, (it also does this on the example page)
https://editor.datatables.net/examples/extensions/rowReorder.html
secondly, my insert behaviour uses a hidden field which automatically assigns a value to my field, but I just noticed that it always inserts at #10 if there are 10 or more rows.
here is a snippet from the editor code...
fields: [ {
label: "Order:",
name: "refeventtype.ListOrder",
type: "hidden",
def: function () {
var nextSeqNum = table
.column(0)
.data()
.sort()
.reverse()[0];
//console.log(nextSeqNum);
if (nextSeqNum == null) {
return 1;
} else {
return parseInt(nextSeqNum) + 1;
}
}
}, {
...
}
]
if i output nextSeqNum to the console, it is always 9, (when there are 9 or more rows). It looks like nextSeqNum variable is being treated as text
This question has an accepted answers - jump to answer
Answers
Thanks for pointing out the multiple delete issue. I'm afraid I don't have an immediate solution for that. I've logged a bug and will look into it as soon as possible.
The
nextSeqNum
issue makes it sounds like you are using server-side processing (i.e. only a limited subset of the data is available on the client-side). Is that the case? If so, you might need to make an Ajax call to the server to find out what the next sequence number should be, or perhaps usepage.info()
to get information about the number of rows in the table.Allan
I believe all of the data is getting to the client side, (there is no filter in my json source)
i set up a test page
http://test3.forthwebsolutions.com/vanilla_eventtypes.php
if there are up to 9 entries in the table, the insert is fine.
if a tenth is added, at the point of insert the nextSeqNum = 9 and the new ListOrder value is set to 10
if an eleventh is added, nextSeqNum is still 9 (and the new ListOrder value is set to 10 and so on)
re the multiple delete, is there a way to prevent multi row delete so only one row can be removed at a time ?
Thanks for the link. The issue is that your numeric data points are all strings. We can see this on the console:
You need to use a sorting function to convert them to be numbers rather than string.
sort()
is just like the Javascriptsort()
method (in fact it is theArray.prototype.sort
method) so you can pass in a function to do the sort as needed (i.e. just parse them as integers). MDN has lots of information about sorting arrays with custom functions.Allan
Thanks Allan, - and thanks for the link
If anyone else has this issue, here is my solution...
As a quick fix for the multi delete problem, I replaced the default editor remove button as follows, seems to work ok.