Using Server JSON to change column name

Using Server JSON to change column name

dreamweaverdjdreamweaverdj Posts: 2Questions: 0Answers: 0
edited April 2012 in General
I'd like to place a column name along with my JSON return, which isn't the problem. I don't know where to HOOK so that I can read the variable and change the column name.

I use fnRender on each column and I'm able to retrieve the json object. How do you do it right before the table renders or right after the table renders?

I would simply like to $('#column2').html(object.customvariable);

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Use fnInitComplete where you can do exactly as you suggest :-)

    Allan
  • dreamweaverdjdreamweaverdj Posts: 2Questions: 0Answers: 0
    indeed fnInitComplete does fire when the table has finished drawing; however, there is no access to the json array that came from the server.

    [code] jukebox=$('#jukebox').dataTable( {
    "bProcessing": true,
    "sScrollY": "600px",
    "bServerSide": true,
    "aoColumns":[{"sWidth":"60px"},{"fnRender":function(o,val){return unescape(o.aData[1]);}}],
    "sAjaxSource": "/gbmusic.nsf/musicList?open&gb=99&client=guest","iDisplayLength":100,
    "bJQueryUI":true,"bFilter":false,"bSort":false,"sPaginationType":"full_numbers",
    "fnServerParams": function (aoData) {var x=Math.random();aoData.push({ "name": "list", "value": chart})},
    "fnInitComplete":function(oSettings,json){
    var t='';
    try{t=json.title}catch(e){t=jTitle}
    $('#column2').html(t)}
    } );
    [/code]

    Originally I simply tried to alert(json.title) but no such luck (object not found). Then I tried to display the entire object. Object not found.

    I have the NAMES of columns as part of the return value. I simply want to grab the values from the json array and use jquery to modify a element.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    That's odd. As you can see in this example ( http://live.datatables.net/isumup/edit#javascript,html ) it should work. Can you link me to a test page that shows the problem please?

    Thanks,
    Allan
This discussion has been closed.