chandan
chandan

Reputation: 104

how to call render function of custom columns in datatable

Hi some one please help on the below logic.

I use to get a dynamic columns from the user, based on that i need to create a dataTable, i have written the below code to read the columns, i need to apply the render function from some columns which have which will display the code value, please share me some idea how to do that

function createDataTableColumns(ColumnsName)
{
  var colum = ColumnsName.split(",");
  $.each(colum, function (i, item) {
    var operationColumns = new Object();
    operationColumns.sTitle = item;
    operationColumns.data = item;
    operationColumns.push(operationColumn);

  })
}

function fnCreateTable(Data, tableID) {
  if ($.fn.dataTable.isDataTable('#' + tableID)) {
    var table1 = $('#customRptTable').DataTable();
    table1.destroy();
    $('#' + tableID + 'tbody').unbind('click');
  }
  $("#divOperation").show();
  debugger;
  var tableLicense = $('#' + tableID).DataTable({
    "data": Data,
    "aoColumns": operationColumns,
    "aaSorting": [],
    "bAutoWidth": true,
    "bPaginate": true,
    "searching": false,
    "sScrollX": "100%",
    "sScrollXInner": "100%",
    "scrollCollapse": true,
  });

  $("#divOperation").show();
};

Upvotes: 2

Views: 3566

Answers (1)

suyesh
suyesh

Reputation: 659

You can define columns and in side that u can use render. Target attribute allows you to define which column you are changing. You no need to loop, render function parameter itself is each value of the targeted column.

 var tableLicense = $('#' + tableID).DataTable({
    "data": Data,
    "aoColumns": operationColumns,
    "aaSorting": [],
    "bAutoWidth": true,
    "bPaginate": true,
    "searching": false,
    "sScrollX": "100%",
    "sScrollXInner": "100%",
    "scrollCollapse": true,
"columnDefs": [ {
    "targets": 0,
    "data": null, // Use the full data source object for the renderer's source
    "render": function(data, type, full, meta){
        // here call your method
     }
  } ]
  });

Upvotes: 1

Related Questions