Attach renderer to column after initialization?

Attach renderer to column after initialization?

Martin@hecoMartin@heco Posts: 12Questions: 5Answers: 0

I have a datatable, which is recieving the column data and definition from a webservice. Some columns may exist or may not exist, depending on the webservice data provided. Specific columns should be rendered in a different way, so I've written a renderer for those.

However, I would only like to use these render functions for specific columns (in my example I need to insert a link into all cells of this column). To keep frontend and backend separated, I do not want to decide the rendering in the backend webservice, but in the frontend.

Is it possible to attach a render function to a specific column after initialization? Something along this pseudocode

// ... webservice call outside of datatable into xhrData ...
var api = $("#example").DataTable(
    "columns": xhrData.columns,
    "data": xhrData.data,
    // ...);

if (api.column("price:name") != undefined) {
    api.column("price:name").render(function (a, b, c, d) {
        // ... do magic ...
        return changedResult;
    });
}

This question has an accepted answers - jump to answer

Answers

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

    Is it possible to attach a render function to a specific column after initialization?

    No - sorry. This is not something that can be defined after initialisation.

    You would need to loop over xhrData.columns before you initialise the table and add the rendering methods as needed there.

    Allan

This discussion has been closed.