Dynamically build DataTable based on Data from Ajax /Server Side Processing

Dynamically build DataTable based on Data from Ajax /Server Side Processing

docturdoctur Posts: 5Questions: 1Answers: 0

Hi All,

I am trying to build a datatable where I can customize the column names the users should see (based on role). I do not want to create a datatable for each role. I want the datatable to dynamically build based on the data that is got from the server side ajax json data. I am sending column name: data format in json. Is this possible? Will the captions dynamically generate too? Does anyone have a working example as I am okay with Javascript but not great with jQuery?

Answers

  • rocheroche Posts: 4Questions: 1Answers: 0

    how about adding the column title as a data attribute to the table,
    get it using javascript then build the header (thead) before initializing datatable,
    initialize datatable.

    that's what i do for mine.

    i just found this (so haven't tried it yet) but maybe you could try using columns.title options : https://datatables.net/reference/option/columns.title

    and instead of using javascript to build the thead element, just pass the variable where you store the title (possibly in JSON format) into datatable columns option. (this is what I do to set dynamic column.data source)

  • docturdoctur Posts: 5Questions: 1Answers: 0

    Do you have a working example of this that I can refer? As mentioned I am not good with jQuery and have basic JS knowledge.

This discussion has been closed.