Dynamic column set with mRender function set dynamically

Dynamic column set with mRender function set dynamically

stmk69stmk69 Posts: 1Questions: 1Answers: 0

Hi,
I have a dynamic table, and I would like to set the columns and mRender function of the data dynamically.
Version of dataTable is 1.10
Here is my code:

var oTable = $('#' + tblId).dataTable({
"lengthMenu": [6, 18, 24, 26, 48],
"bServerSide": true,
"sAjaxSource": url,
"sServerMethod": "POST",
"bProcessing": true,
"sDom": 'lfrtip',
"fnServerParams": function (aoData) {
aoData.push({ "name": "searchString", "value": json_data });
},

"aoColumnDefs": [{
"aTargets": [0],
"mRender": function (data, type, full) {
return '<input type=\"checkbox\" name=\"chkCompare_' + data + '\" id=\"chkCompare_' + data + '\" class=\"compareCheckBox\" />';
},
},
{ "className": "compareCheckBox", "targets": [0] },
{
"aTargets": [1],
"mRender": function (data, type, full) {
return full[6] + ' title=\"' + data + '\">' + data + '</a>';
}
},
{
"aTargets": [2],
"mRender": function (data, type, full) {
return full[6] + ' title=\"' + data + '\">' + data + '</a>';

            }
        },
    {
        "aTargets": [3],
        "mRender": function (data, type, full) {
            return full[6] + ' title=\"' + data + '\">' + data + '</a>';
        }
    },
    {
        "aTargets": [4],
        "mRender": function (data, type, full) {
            return full[6] + ' title=\"' + data + '\">' + data + '</a>';
        }
    },

],
})
I have in the last column the link which should be set on each column, it is the same for each column.
Is it possible to make this settings dynamically, because number of the columns is not the same. That means that I have the same table once build with 3 columns, once with 4 columns. I always put the link in the last column.

Thank you.

Answers

  • tasso22tasso22 Posts: 4Questions: 1Answers: 0

    @stmk69 - Did you happen to find a solution to this? I too, am encountering the same problem. The number of columns/data in my table will be different depending on the user type. If possible, I prefer to have configuration/data that will feed mrender the function it needs to do special formatting that is required.

    Columns are being outputted dynamically from a datasource similar to the following post:
    http://datatables.net/forums/discussion/6260/dynamic-column-names

    It's just the mrender that I'm getting stuck on to work correctly when it is being driven from configuration/data source.

This discussion has been closed.