Reorder and Dynamic add in one action

Reorder and Dynamic add in one action

MurasakiMurasaki Posts: 1Questions: 1Answers: 0

Hi,

Currently, both reorder and add new row work individually, but if I reorder and then add a new row, the order resets to what it originally was.

The data is stored in a table which is written by Handlebars, the order number is refreshed manually.

I think whats happening is DataTables is trying to redraw what it thinks is the order, Is there a way to suppress reordering on a draw?

My initialisation

        dataTable = $("#content-Table").DataTable({
            "destroy": true,
            "searching": false,
            "paging": false,
            "info": false,
            "lengthChange": false,
            "processing": true,
            "scrollY": "calc(100vh - 30rem)",
            "scrollCollapse": true,
            "ordering": false,
            "language": {
                "emptyTable": "There were no rules retrieved to display."
            },
            rowReorder: {
                update: false,
            },
            columnDefs: [
                { orderable: true, className: "reorder", targets: 0 },
                { orderable: false, targets: "_all" }
            ],
            "lengthMenu": [[10, 25, 50], [10, 25, 50]]
        });
        dataTable.on("row-reorder",
                function(e, diff, edit) {
                    if (!diff.length)
                        return;

                    recalculateOrder();

                    var saveButton = new SaveButton(".save-pr-buttons");
                    saveButton.Show();
                })
            .on("pre-row-reorder",
                function(e, node, index) {
                    if (e === undefined)
                        return;
                });

My add new row:

        dataTable.row.add($(templateHtml)).draw();

        recalculateOrder();

Answers

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

    There is a page option for the draw() API that doesn't update the ordering and searching. Maybe that will do what you want.

    Kevin

This discussion has been closed.