Statesave + colreorder + columndefs COMBO PROBLEM

Statesave + colreorder + columndefs COMBO PROBLEM

itajackassitajackass Posts: 121Questions: 37Answers: 3

I've found a bug when I use STATESAVE with COLREORDER and COLUMNDEFS:

  "aaSorting": [[ 3, "desc" ]],
  colReorder: true,
stateSave: true,
  "columnDefs": [
        {
                targets: [1],
                data: {
                    _: "1.display",
                    sort: "1.@data-order",
                    type: "1.@data-order"
                }
            }
        ]

Supposing my table has 3 columns. And second column (index = 1) has a custom ordering from columndefs.

If I change col reorder and put date birth for example in first position and reload the page, state is saved so now date birth is on first index = 0. And columndefs not work.

<table>
<thead>
 <tr>
    <th class="name">Name</th>
    <th class="date">Date birth</th>
    <th class="comment">Comment</th>
</tr>
</thead>
<tbody>
  <tr>
      <td>John</td>
      <td data-order="2000-04-01">01/04/2000</td>
      <td>text...</td>
  </tr>
  <tr>
      <td>Doe</td>
      <td data-order="2001-04-01">01/04/2001</td>
      <td>text...</td>
  </tr>
 <tr>
      <td>John</td>
      <td data-order="2002-04-01">01/04/2002</td>
      <td>text...</td>
  </tr>
  <tr>
      <td>John</td>
      <td data-order="2003-04-01">01/04/2003</td>
      <td>text...</td>
  </tr>
</tbody>
</table>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,400Questions: 26Answers: 4,787
    edited August 2019 Answer ✓

    I would try using columnDefs.targets with the class of date instead of specifying a specific column.

    Kevin

  • itajackassitajackass Posts: 121Questions: 37Answers: 3

    Sorry for the late... so... how can i write this (instead of 1 ??):

          data: {
                    _: "1.display",
                    sort: "1.@data-order",
                    type: "1.@data-order"
                }
    
  • colincolin Posts: 15,174Questions: 1Answers: 2,589

    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

  • itajackassitajackass Posts: 121Questions: 37Answers: 3

    ok solved:

    "columnDefs": [
        {
                targets: 'date',
                data: {
                    _: "date.display",
                    sort: "date.@data-order",
                    type: "date.@data-order"
                }
            }
        ]
    
This discussion has been closed.