Server does not receive current order/sort column

Server does not receive current order/sort column

dannerfrdannerfr Posts: 4Questions: 2Answers: 0

DataTables 2.3.2
Firefox 140.0.4

Hi there!

const table = new DataTable('#orders',
{
    ajax: '/dt?table-id=orders',
    columns: 
    [
        {data: 'timestamp',
         render: DataTable.render.datetime('MMMM DD YYYY, HH:mm:ss')
        },                  
        {data: 'number'},
        {data: 'source'},
        {data: 'status'},
        {data: 'email'}
    ],          
    order: [[0, 'desc']],   // timestamp
    lengthMenu: [20, 50],   // page size selection
    search: 
    {
        return: false   // filter as you type
    },          
    processing: true,
    serverSide: true
});

When receiving the query map in my callback (embedded HTTP server) I expected DataTables to reflect the user's order/sort selection much like it does by passing a searchable string. Instead, it always passes the predefined order column (index 0 = "timestamp") with "asc" or "desc". I called table.order() to find out what's the current internal order setting and it's correct, eg. if the user wants to sort on column "number" index 1 returns. So I wonder when calling table.ajax.reload() or table.ajax.url('/dt?table-id=orders').load() for a server side refresh why DataTables does not pass this up-to-date information, too?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 64,743Questions: 1Answers: 10,713 Site admin
    Answer ✓

    Can you link to a test case showing the issue please?

    I don't see anything there that would cause the order parameter that is being sent to the server on each request to not be the end user's sort column selection.

    Ordering works with server-side processing in this example, so I'd need to see a test case showing the problem please.

    Allan

  • dannerfrdannerfr Posts: 4Questions: 2Answers: 0

    Thanks Allan :)

    You're right: the current sorting columns are passed to my server: By mistake I ignored
    to interpret order[0][column] = 1 for 1 being the index. It would have been clearer if the field would have been named order[0][index] = 1 instead ;)

    Frank

  • allanallan Posts: 64,743Questions: 1Answers: 10,713 Site admin
    Answer ✓

    Hah, but it is index 0. There are two hard problems in computer science.... ;)

    Good to hear you got it working.

    Allan

Sign In or Register to comment.