Determine column order when using ColReorder

Determine column order when using ColReorder

donatodonadonidonatodonadoni Posts: 3Questions: 1Answers: 0

I am using DataTables with Ajax. I am using the ColReorder extension and everything works, including the Ajax calls. However, when I reorder a column and then click next page or search, columns do not preserve new order.

I look at request sent to server and I cannot see any changes that would indicate a new column order:

"draw"=>"3", 
"columns"=>{

"0"=>{"data"=>"0", "name"=>"", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, 
"1"=>{"data"=>"1", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"2"=>{"data"=>"2", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"3"=>{"data"=>"3", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"4"=>{"data"=>"4", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"5"=>{"data"=>"5", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"6"=>{"data"=>"6", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"7"=>{"data"=>"7", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"8"=>{"data"=>"8", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"9"=>{"data"=>"9", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"10"=>{"data"=>"10", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}

}, 

The above params look no different from the ones below, even though I rearranged columns between the request:

 Parameters: {"classification_code_id_is"=>"5cad0dc73ed1496086000007", 
"draw"=>"4", 
"columns"=>{
"0"=>{"data"=>"0", "name"=>"", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, 
"1"=>{"data"=>"1", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"2"=>{"data"=>"2", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"3"=>{"data"=>"3", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"4"=>{"data"=>"4", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"5"=>{"data"=>"5", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"6"=>{"data"=>"6", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"7"=>{"data"=>"7", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"8"=>{"data"=>"8", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"9"=>{"data"=>"9", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, 
"10"=>{"data"=>"10", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}
}, 

"order"=>{"0"=>{"column"=>"8", "dir"=>"desc"}}, 
"start"=>"10", "length"=>"10", "search"=>{"value"=>"", "regex"=>"false"}, "_"=>"1555023437295"}

How can I determine the new order?

Answers

  • donatodonadonidonatodonadoni Posts: 3Questions: 1Answers: 0

    I resolved part of issue. I use objects instead of array of indexes now. But still it sends ajax calls using original order. When moving columns, the change is not sent in ajax request.

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @donatodonadoni ,

    The column order shouldn't matter if you're using objects, as shown in the example here. If the column order affects what the server returns, you can add the column order (colReorder.order()) into the data sent to the server with ajax.data,

    Cheers,

    Colin

  • donatodonadonidonatodonadoni Posts: 3Questions: 1Answers: 0

    I fixed the issue. It does send the columns in their new order. Still it was easy for me to persist data on server side with assigning the columns a name attribute so I could easily extract the reordered columns on server from params.

This discussion has been closed.