fnRender issue with 1.8

fnRender issue with 1.8

numberonenumberone Posts: 86Questions: 0Answers: 0
edited April 2011 in DataTables 1.8
hi,

this is not working after the lib updated. it seems like a bug.

[code]

var activated=new Array("Inactive","Active");
.
.
{ "sName": "activated", "fnRender": function (oObj){return activated[oObj.aData[4]];} },

[/code]

it returns "undefined" . its working with 1.7.6 without problem.

Thanks.

Replies

  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    Interesting one. I presume oObj.aData[4] holds either '0' or '1'? Could you possibly post up an example of this problem?

    Thanks,
    Allan
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    yes it holds '0' or '1'

    activated[1] works
    oObj.aData[4] this one returns 0 or 1

    but activated[oObj.aData[4]] returns undefined. :S
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    edited April 2011
    i made it work by doing,

    var activated=new Array(2,3,"Inactive","Active");

    it is meaningless.im sure that something wrong with fnRender..

    it is something returns like "activated[ activated[0] ]" or "activated[ activated[1] ]"
    while using activated[oObj.aData[4]]

    thanx for help ^^
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    If you add the following to your fnRender function, what comes out on the console:

    [code]
    console.log( '{'+oObj.aData[4]+'}' );
    [/code]
    Allan
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    edited April 2011
    var activated=new Array("Inactive","Active");



    console.log( '{'+oObj.aData[4]+'}' );
    {1}
    {_firebugIgnore}
    {0}
    {_firebugIgnore}
    {1}
    {_firebugIgnore}
    {1}
    {_firebugIgnore}
    ..

    console.log( '{'+activated[ oObj.aData[4] ]+'}' );
    {Active}
    {undefined}
    {Active}
    {undefined}
    {Inactive}
    {undefined}
    {Active}
    {undefined}
    {Active}
    {undefined}
    {Active}
    {undefined}
    {Active}
    {undefined}
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    If the render function is trying to get the property _firebugIgnore from your 'activated' array, then that is what is causing the issue. However, where that request is coming from I have no idea!

    I've just tried this:

    [code]
    $(document).ready(function() {
    var a = [ "zero", "one" ];
    $('#example').dataTable( {
    "aoColumnDefs": [
    {
    "fnRender": function (o) {
    return a[ o.aData[0] ];
    },
    "aTargets": [1]
    }
    ]
    } );
    } );
    [/code]
    With this table:

    [code]



    first
    second




    0



    1



    1



    0




    [/code]
    and it seems to work absolutely fine. No errors or weird behaviour in Safari or Firefox.

    Could you post either a link to your page, or your full initialisation code please?

    Allan
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    edited April 2011
    your code is working but mine doesnt

    [code]


    $(document).ready(function () {
    var activated = ["Inactive","Active"];
    var banned = ["Active","Banned"];

    $('#usertable').dataTable({
    'bProcessing' : true,
    'bServerSide' : true,
    'sAjaxSource' : '<?php echo base_url(); ?>admin/users/getusers_byajax',
    "sPaginationType": "full_numbers",
    "bAutoWidth": false,
    "aoColumns": [
    { "sName": "users.id", "bVisible": false },
    { "sName": "users.username" },
    { "sName": "users.email"},
    { "sName": "user_groups.group_name" },
    { "sName": "users.activated", "fnRender": function (o){ return activated[o.aData[4] ] ;} },
    { "sName": "users.banned", "fnRender": function (o){return banned[o.aData[5]] ;} },
    { "sName": "edit", "bSortable": false },
    { "sName": "delete", "bSortable": false },
    ],
    'fnServerData': function(sSource, aoData, fnCallback)
    {
    $.ajax
    ({
    'dataType': 'json',
    'type' : 'POST',
    'url' : sSource,
    'data' : aoData,
    'success' : fnCallback
    });
    },
    });

    });





    Kullan?c?lar










    ID
    Username
    Email
    Plevel
    Activated
    Banned
    Edit
    Delete




    loading..






    [/code]




    and my json :

    [code]
    {"sEcho":1,"iTotalRecords":"7","iTotalDisplayRecords":"7","aaData":[["1","numberone","n1@test.com","1","0","SuperAdmin","D\u00fczenle<\/a>","Sil<\/a>"],["2","admin","admin@admin.com","1","0","Admin","D\u00fczenle<\/a>","Sil<\/a>"],["3","testuser","testuser@test.com","0","0","User","D\u00fczenle<\/a>","Sil<\/a>"],["4","badguy","badguy@badguy.com","1","1","User","D\u00fczenle<\/a>","Sil<\/a>"],["5","test","test@test.com","1","0","User","D\u00fczenle<\/a>","Sil<\/a>"],["6","fw","fw@bunebune.com","1","0","User","D\u00fczenle<\/a>","Sil<\/a>"],["7","user","email@email.com","1","0","User","D\u00fczenle<\/a>","Sil<\/a>"]],"sColumns":"users.id,users.username,users.email,users.activated,users.banned,user_groups.group_name,edit,delete"}
    [/code]
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    I think I might know what the issue is - could you add

    [code]
    "bUseRendered": false,
    [/code]
    to your column definition for the column with the rendering function and let me know what the result is?

    I think the issue is that fnRender is being called twice with server-side processing in 1.8 (intentionally so, but this is an unintentional side effect).

    Thanks,
    Allan
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    edited April 2011
    Thanks Allan,

    i added "bUseRendered": false to the columns and it worked well.

    Regards,
    Yusuf
  • ganapathy_paulrajganapathy_paulraj Posts: 16Questions: 0Answers: 0
    i used the above but still am not able to make it work ,

    [code]

    "aoColumnDefs": [
    { "mDataProp": "Select",
    "fnRender" : function ( oObj ) {
    console.log(oObj.aData[0]);
    console.log(oObj.aData[oObj.oSettings.aoColumns[oObj.iDataColumn].mDataProp]);
    return ' ';
    },
    "bUseRendered": false,
    "aTargets": [ 0 ]
    },
    { "mDataProp": "userName",
    "aTargets": [ 1 ] },
    { "mDataProp": "loginTime",
    "aTargets": [ 2 ] }
    ],
    "fnDrawCallback": function() {
    persistChecked();
    }

    [/code]
This discussion has been closed.