colReorder data incorrectly positioned after refresh

colReorder data incorrectly positioned after refresh

greenman123greenman123 Posts: 10Questions: 5Answers: 0

I have enabled colReorder, I have noticed when rearrange columns they are fine, if I refresh the column headers are in the position I dragged them to - but the column data isn't.

The column data is got throguh my Ajax source, this adds the data in the original order like so:

nestedData[] = 'col1';
nestedData[] = 'col2';

Do I need to get the reordered data to use my in my array indexes? If so how can I do this (note at the point of declaring the column data array indexes I am in PHP).

Answers

  • colincolin Posts: 3,648Questions: 0Answers: 645

    Hi @greenman123 ,

    How do you 'refresh the column headers' - that's probably key here? As shown in the examples here, the data and the header stay in sync. If that's not working for you, that's not a known issue.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • greenman123greenman123 Posts: 10Questions: 5Answers: 0
    edited January 16

    I had my array being passed back from my PHP function incorrectly (or in the wrong format required).

    I needed to declare the array like so in my PHP:

    $nestedData = array();
    $nestedData[$i]['col1'] = 'col1 value'
    $nestedData[$i]['col2'] = 'col2 value'

    Then send it like this:

    $json_data = array(
    'recordsTotal' => count( $ids ),
    'data' => $nestedData
    );

    echo json_encode( $json_data );

    Note I was using a second parameter of JSON_FORCE_OBJECT on the encode that I didn't need.

    I then declare in JavaScript in the columndefs like so:

    "columnDefs": [
    { "data": "col1", "name": "id", "targets": 0},
    { "data": "col2", "name": "id", "targets": 0}
    ]

    This was the data in the JavaScript matches the array key I am sending in the ajax PHP, which in turn is the object key when console logged from the table data.

    I think?! Works fine for me anyway!

    Note the refresh in the reply above from @colin was just a browser refresh, but it obviously couldn't match up the JavaScript column def with the data coming back from AJAX.

Sign In or Register to comment.