row-reorder event not fired

row-reorder event not fired

jidejide Posts: 1Questions: 1Answers: 0

I have generated a datatable using the latest release Datatables 1.10.15 along with the latest of all the extensions. Row reorder is functioning, however I want to update the ordering back to the server. Unfortunately the row-reorder event never gets called. Here is the code:

   var table = $(tableId).dataTable({
            ajax: url,
            columns: [
                { data: 'SortIndex', className: 'reorder' },
                { data: 'MeasureId' },
                { data: 'MeasureGroup', "className": "text-right" },
                { data: 'Type', "className": "text-left" },
                { data: 'Display', "className": "text-left kitt-truncate" },
                { data: 'Location', "className": "text-left kitt-truncate" },
                { data: 'Status', "className": "text-left" },
                { data: 'ActualQuantity', "className": "text-right" },
                { data: 'CostPerUnit', "className": "text-right" },
                { data: 'CustomerIncentive', "className": "text-right" },
                { data: 'EnergyDeltaKwh', "className": "text-right" },
                { data: 'SummerLoadReduction', "className": "text-right" },
                { data: 'WinterLoadReduction', "className": "text-right" },
                { data: 'FuelDeltaMmbtu', "className": "text-right" },
                {
                    data: 'CanScreen',
                    "className": "text-center"
                }
            ],
            "sAjaxDataProp": "",
            rowReorder: true,
            dataSrc: "",
            "bPaginate": false
        });
        table.on('row-reorder', function (e, details, changes) {
            alert("hello");
        });

I have also tried it using editor with example on this page:
https://datatables.net/reference/event/row-reorder

and that returns with this: Uncaught TypeError: Cannot read property 'multiSet' of undefined

Thanks!

Answers

  • kthorngrenkthorngren Posts: 21,152Questions: 26Answers: 4,919

    Instead of this:

             rowReorder: true,
             dataSrc: "",
    

    Maybe you need to do something like this:

        rowReorder: {
            dataSrc: 'SortIndex'
        }
    

    You may need to define that field in the Editor also.

    Kevin

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    Hi,

    Change:

    var table = $(tableId).dataTable({
    

    to be:

    var table = $(tableId).DataTable({
    

    The difference is that the DataTable() returns an API instance, rather than a jQuery object (which dataTable() does).

    Its a bit iccky, but both DataTables and jQuery have on() methods, which is why you won't get any Javascript errors. But with DataTables' on() method it will automatically listen for events in the DataTables namespace, where as for jQuery's method you need to use row-reorder.dt.

    What Kevin mentioned I don't think will resolve your issue as such, but it is a valid point - there is no dataSrc option at the bottom level of the DataTables configuration.

    There is ajax.dataSrc and rowReorder.dataSrc. There is a good chance you will need to define both (and remove the legacy sAjaxDataProp).

    Regards,
    Allan

  • timbcusicktimbcusick Posts: 21Questions: 6Answers: 0

    Allan,

    That fixed it! Thanks Kevn. I had tried playing with dataSrc but obviously had no impact as I had a key ingredient missing.

    Tim

This discussion has been closed.