Using momentJS in datatables.

Using momentJS in datatables.

utkantutkant Posts: 8Questions: 4Answers: 0

Hi!

How would I use momentJS in datatables?

Say I have a column with a momentJS object and I want to update that column so that it showed me the correct information in the browser. How would I do that?

And as a followup. How would I update this if I wanted to change the format of the output from the momentJs object?

This question has an accepted answers - jump to answer

Answers

  • utkantutkant Posts: 8Questions: 4Answers: 0
    edited June 2014

    I managed to get this working by using the render function in the aColumnDefs setting. This now works beautifully. But I have one issue. If I want that function to be rerun on or before a draw on the table so that I can switch the format of the output how would that be done?

    "aoColumnDefs": [
        {
            "aTargets": dates,
            "render": function (data, type, row) {
                data = moment(data);
                return $filter("csDate")(data);
            }
        }
    ],
    

    How would I go about to get the render function rerun during a call to the draw() function

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    You would need to invalidate the row (row().invalidate()) to have the data refreshed.

    Allan

  • utkantutkant Posts: 8Questions: 4Answers: 0

    Thanks Allan.

    If you want all rows you can use rows().invalidate(). Just a tips for everyone else who needs this.

This discussion has been closed.