Why Sortable is just fetching the first 10 entries in parameters from DataTable?

Why Sortable is just fetching the first 10 entries in parameters from DataTable?

iftikharuddiniftikharuddin Posts: 18Questions: 5Answers: 0

I'm trying to implement ordering functionality in datatable. Requirement is simple, when a user drag a row for repositioning the respective row position/order field value should be incremented/decremented respectively in database!

I tried the below but sortable **function is just fetching the 1st 10 entries ids from the DataTable in **parameters variable.

How can I get all the available entries ids from the datatable in my params variable. The DataTable is in paginated form so I want to get all the records ids in parameters variable when someone is reordering records in DataTable.

// The below functionality is for ordering categories
var $sortable = $( ".resources-categories-table > tbody" );
$sortable.sortable({
    stop: function ( event, ui ) {
        var parameters = $sortable.sortable( "toArray", { attribute: 'data-id' });
        $.ajax({
            url: '<?php echo $this->CxHelper->Route('eb-admin-change-resource-category-order')?>',
            type: 'POST',
            data: { values: parameters },
            success: function (data) {
                cx.common.data.cxAdminDataTables.ResourceCategory.cxAdminDataTable("reloadAjax");
            }
        });
    }
});

PHP

public function changeResourceCategoryOrderAction() {
    $values = $this->request->get( 'values', null );
    var_dump($values);exit;
}

Answers

  • iftikharuddiniftikharuddin Posts: 18Questions: 5Answers: 0
  • iftikharuddiniftikharuddin Posts: 18Questions: 5Answers: 0
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    jQuery UI Sortable has no knowledge of DataTables and the fact that DataTables has removed rows from the document for paging. So it can't include those other rows. There might be an API in Sortable to allow for that, but I don't know.

    Have you had a look at our own RowReorder extension. Combined with Editor it will update to the db.

    Allan

This discussion has been closed.