Assign column names via an attribute in ?

Assign column names via an attribute in ?

guiceguice Posts: 5Questions: 0Answers: 0
edited May 2012 in General
I have a code base where I have a few tables of variable widths, all running the same server-side processing methods. I need to assign column names, but due to the static nature of aoColumns or aoColumnDefs, I can't use them.

Is there a way to have DT read custom attributes on the tag for the column names to send with the server-side data? Something like Name. Clicking the sort column would send the "username" column name.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Am I right in saying that your HTML is static - i.e. its already in the DOM when you initialise DataTables? If so, can you simply build an aoColumns array with sName server for the column based on what you can read from the DOM?

    Allan
  • guiceguice Posts: 5Questions: 0Answers: 0
    HTML is static, but I have several tables of different number of columns. Ideally, I want to use one .dataTables() call for all tables (they are similar), but because aoColumns is dependent on number of columns, I can't use that to assign sNames to my columns. And since each table has(can have) different columns, I can't use aoColumnDefs either.

    I would like some way for DT to assign sName column names based on a custom attribute in .
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > I would like some way for DT to assign sName column names based on a custom attribute in .

    That does sound sensible. I'm afraid that it isn't possible at the moment, but for 1.10 I'm going to be looking at increasing how sName can be used in the API, and this ability will be one of the things that I look at.

    Allan
  • guiceguice Posts: 5Questions: 0Answers: 0
    Okay. Thanks. In the mean time then I've added a hook in fnServerData to read in all the headers for the currently selected table, and pass them across in a POST variable. It's working exactly as I wanted:

    [code]
    fnServerData: function ( source, data, callback ) {
    var headers = [];
    $('thead th', this).each(function() {
    headers.push($(this).attr('dtName'));
    });
    ....
    [/code]
This discussion has been closed.