change column name on the fly

change column name on the fly

hardlickhardlick Posts: 14Questions: 0Answers: 0
edited December 2009 in General
how can i change the column name on the fly.
$(rpta).each(function(){
olisttable.fnAddData( [
""+ this.prvid +"",
this.prvtype,
""+this.prvlname + ", " +this.prvfname+"",
this.addrzip,
this.prvpracname,
this.address
]);
when return the data from json, how can i change the column name too?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi hardlick,

    There isn't a built-in method to change the column name on-the-fly. What you will need to do is simply take the data from your JSON return and then use standard DOM methods to update the column titles as you require.

    Regards,
    Allan
  • hardlickhardlick Posts: 14Questions: 0Answers: 0
    so, i can edit the column name how via json?, example:



    ID
    Specialist Type
    Name
    ZipCode
    Specialist
    Practice Address






    $("#ides").text('new column name');
    $("#esp").text('new column name2');

    with this way?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Yup - exactly like that (although document.getElementById('ides').innerHTML = "new column name"; is quicker ;-) ).

    DataTables doesn't really care what the title of the column is, so you can change it as you wish.

    Regards,
    Allan
  • hardlickhardlick Posts: 14Questions: 0Answers: 0
    ahhh ok, thanks a lot!, ;)
  • bilbodigibilbodigi Posts: 18Questions: 0Answers: 0
    Don't forget to add the sort icon.

    document.getElementById('visitsThisPeriodText').innerHTML = 'New text';
This discussion has been closed.