DataTables 2.0.0 - columnDefs "_all"

DataTables 2.0.0 - columnDefs "_all"

uYopuYop Posts: 3Questions: 1Answers: 0
edited February 29 in Free community support

Hi.
Since the recent update, this code is not working anymore

columnDefs: [
        {
            targets: '_all',
            render: function (data, type, row, meta) {
                if ($(meta.settings.aoColumns[meta.col].nTh).data('type') === 'date') {
                    if (type === 'display' || type === 'filter') {
                        return formatFrenchDate(data);
                    }
                }
                return data;
            }
        }
    ],

Is there any easier way to make it work ?
Thank you so much for the continued support you are providing.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Should have been fixed with 2.0.1. Have you tried that update?

    Allan

  • uYopuYop Posts: 3Questions: 1Answers: 0

    Hello Allan,

    Thank you for your answer.
    Unfortunately yes, I am already using the 2.0.1 version.

    This is how I use it my <th>

    <th class="text-900 pe-1 align-middle" data-type="date">Date achat</th>

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Ah, sorry, I see the issue now. aoColumns[].nTh no longer exists due to the support for multi-row headers. Its an internal property, so I wouldn't recommend using it, or anything else in the settings object as things can, do, and will change as you see here.

    With v2, what I would suggest you do to match the current behaviour, is to use the new DataTable.type() method to assign a renderer to columns which are detected as a date type.

    DataTable.type('date', 'render', function (data, type, row) {
      if (type === 'display' || type === 'filter') {
        return formatFrenchDate(data);
      }
      return data;
    });
    

    Then that renderer will be used for anything detected as a date type (assuming the data in that column is detected as such). Here is a little test case showing that.

    However, I actually think there is a better solution, you might want to take a look at the DataTable.render.date() built in renderer. There are a collection of examples here. With that, it will take an ISO8601 string and format it for the user's locale automatically.

    Allan

  • uYopuYop Posts: 3Questions: 1Answers: 0
    edited March 1

    Thank you !

Sign In or Register to comment.