Filtering and display get the rendered string

Filtering and display get the rendered string

montoyammontoyam Posts: 568Questions: 136Answers: 5

I don't understand what is going on in line 5 in one of the examples posted: https://editor.datatables.net/examples/plug-ins/fieldPlugin.html

Since this is for the DataTabe, I guess I am confused as to when type would not be 'display' and the zero or one would be displayed instead of ToDo/Done

            {
                className: "center",
                data: "done",
                render: function (data, type, row) {
                    if ( type === 'display' || type === 'filter' ) {
                        // Filtering and display get the rendered string
                        return data == 0 ? "To do" : "Done";
                    }
                    // Otherwise just give the original data
                    return data;
                }
            }

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited April 2020 Answer ✓

    Orthogonal data is explained in this doc:
    https://datatables.net/manual/data/orthogonal-data

    To visualize this put console.log( type ) between lines 4 and 5. On table load you will see the render function is run for display and filter. If you then sort the column you will see it run for the sort operation. You can also use the render function for the export buttons as shown in this example.

    So basically the above results in displaying Done or ToDo. Also you can filter the table by typing Done or ToDo instead of 0 or 1. But the sorting is performed using 0 and 1 instead of the words.

    Does this help?

    Kevin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    awesome explanation. thank you.

This discussion has been closed.