Icon replacement for values

Icon replacement for values

cuthbecuthbe Posts: 4Questions: 0Answers: 0
edited October 2012 in General
All how do we change a value say true in one of the columns to show an icon?

Replies

  • robertbrowerrobertbrower Posts: 158Questions: 1Answers: 0
    edited October 2012
    By means of the mData & mRender options.
  • cuthbecuthbe Posts: 4Questions: 0Answers: 0
    edited October 2012
    Hi thanks just saw that in the docs.

    [code]

    "aoColumns": [
    {
    "sClass": "center",
    "fnRender": function( oObj ) {
    return oObj.aData[0]+' '+ oObj.aData[3];
    }
    }
    ]

    [/code]

    So this will render column 1. If I have a table of 9 columns but only want to render column 7,8,9 and the rest leave as they are, how do you do that?
  • cuthbecuthbe Posts: 4Questions: 0Answers: 0
    Found it but just setting the others to null.

    [code]

    "aoColumns": [
    {
    "sClass": "center",
    "fnRender": function( oObj ) {
    return oObj.aData[0]+' '+ oObj.aData[3];
    }
    },
    null, //Forname
    null, //Surname
    null, //Email
    null, //REgion
    null, //Telephone
    null, //Expired
    null, //Locked
    null, //Logged on
    null // created
    ]

    [/code]
  • robertbrowerrobertbrower Posts: 158Questions: 1Answers: 0
    You should use mData and mRender over fnRender as fnRender will be deprecated in the next DataTables release. But if you want to use fnRender, you provide the "aoColumnDefs" options as follows:

    [code]
    , "aoColumnDefs": [
    {
    "aTargets": [7, 8, 9] // <- the effected columns
    , "fnRender": function (obj) {

    var text= obj.aData[obj.iDataColumn];
    if (text == "Y") {
    return ""; // <- return what should be rendered
    } else {
    return ""; // <- return what should be rendered
    }
    }
    , "bUseRendered": false // <- tells DataTables to sort on the original "Y" & "N" values and not the "" tag that is rendered.
    }
    ]
    [/code]
This discussion has been closed.