Adding custom attributes to Datatable

Adding custom attributes to Datatable

karthi_bkarthi_b Posts: 3Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
I would like to customize Datatable to include my own attributes which I want to initialize while the datatable is created.

For example,

[code]
var oTable = jQuery('#example').dataTable({
'iDisplayLength' : 20,
'aoColumnDefs' : [
{'sType': 'custom-date','aTargets': [1]},
{'bSortable': false,'aTargets': [5]}
],
'retainFirst': true //custom attribute
});
[/code]

I would like to add a custom attribute 'retainFirst' to datatable which I want to initialize as either true/false. How can i do this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Just exactly as you have done. DataTables keeps the initialisation object that it was given in the oInit property of its settings object ( fnSettings ) for a table. So you could access your property using table.fnSettings().oInit.retainFirst when you need to in your code.

    Allan
  • karthi_bkarthi_b Posts: 3Questions: 0Answers: 0
    Great.. Its working!! :) Thanks for ur quick response...
  • robertmazzorobertmazzo Posts: 22Questions: 0Answers: 0
    Hi Folks,
    Quick question on this:

    I have 5 columns in my table as shown in my headers

    Trade IdDescriptionContributionTermDate

    and I'm trying to understand how to implement that oTable code above.

    Using this template, how to I specify the column names as well as some custom attributes I need:

    var oTable = $('#pftable').dataTable({
    'sScrollY': "500px",
    'aoColumnDefs': [

    ]
    });
This discussion has been closed.