set the "title" attr for server-side data

set the "title" attr for server-side data

nneverweinneverwei Posts: 2Questions: 0Answers: 0
edited May 2012 in General
with server-side data, the is auto generate by datatables, but if there any way to set the "title" attr for those sever-side data?
()

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    You need to use a callback function such as fnCreatedCell or fnDrawCallback to add the attributes you want to the DOM elements.

    Allan
  • nneverweinneverwei Posts: 2Questions: 0Answers: 0
    ok, thanks a lot~
  • LuchianLuchian Posts: 4Questions: 0Answers: 0
    edited May 2012
    In the fnRender I return a div to which I can then set the title - I can then use (for my title value) any field from my passed-in oObj.
    Ex: In the code below, I display in the table cell a short string repesenting a date (actually, only day and month) while in the title (aka tooltip for that cell), I display the full date and time including timezone, converted from the json as serialized by mvc (thus the extra code to read that date):
    [code]
    var otbl = $('#someTable').dataTable({
    "sAjaxSource": someUrl,
    "fnServerData": function (url, data, callback) {
    $.ajax({
    "url": url,
    "data": data,
    "success": callback,
    "contentType": "application/x-www-form-urlencoded; charset=utf-8",
    "dataType": "json",
    "type": "POST",
    "cache": false,
    "timeout": 60000,
    "error": function (jqXHR, textStatus, errorThrown) {
    if (otbl != undefined)
    otbl.fnProcessingIndicator(false);
    if (textStatus === "timeout") {
    alert("Downloading data has timeout. ");
    } else {
    alert("Downloading data has failed. Error: " + textStatus);
    }
    }
    });
    },
    "sDom": 'ritS',
    "aoColumns": [{ "mDataProp": "LogDateDisplay", "fnRender": function (oObj) {
    return '' +
    oObj.aData.LogDateDisplay + ''; } }
    ],
    "bServerSide": true
    });
    [/code]
    where the code to parse the mvc json date is (and you can ignore it as not part of your question though):
    [code] new Date(parseInt(oObj.aData.LogDate.replace("/Date(", "").replace(")/", ""), 10))[/code]

    hth
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Looks good - thanks for sharing your solution with us. fnRender is certainly a good option if you want to build the whole HTML string dynamically - if you want to add the attribute to a node, then fnCreatedCell or fnCreatedRow are there to provide that option.

    Allan
This discussion has been closed.