conditions in mRender

conditions in mRender

tester1tester1 Posts: 53Questions: 14Answers: 1
edited August 2014 in Free community support

Hi i am using latest version of datatables.

I want to display some records but with if else-if condition from mRender

$(document).ready( function() {
  var oTable = $('#example').dataTable( {
        "bProcessing": true, 
        "bServerSide": true,
        "sAjaxSource": "test_list_db.php",
    "aoColumnDefs": [ {
      "aTargets": [ 2 ],
      "mData": "null",
      "mRender": function ( data, type, full ) {
                                if(full[20] != 0 ){
                                var status = '<div id="container">\n\
                                        <a href="test_list.php?a='+full[20]+'&ab='+full[21]+'" class="click_'+full[22]+'">\n\
                                        '+full[20]+' - '+full[23]+'  \n\
                                        </a><br \>\n\  </div>';
                                        
                                } else if(full[21] != 0){   //  -- if this record is ZERO then will not be seen 
                               var status = '<div id="container">\n\
                                        <a href="test_list.php?a='+full[0]+'&ab='+full[20]+'" class="click_'+full[0]+'">\n\
                                        '+full[21]+' - '+full[24]+'  \n\
                                        </a><br\>\n\ </div>';
                                } else if(full[22] != 0){
                               var status = '<div id="container">\n\
                                        <a href="test_list.php?a='+full[0]+'&ab='+full[20]+'" class="click_'+full[0]+'">\n\
                                        '+full[22]+' - '+full[25]+'  \n\
                                        </a><br\>\n\ </div>';
                                }
                  return status;
      }
    } ]
  } );
} );

also how i can use if condition under anchor tag of it , i means like :

<a href="test_list.php?a='+full[20]+'&ab='+full[21]+'" class="click_'+full[22]+'">\n\ '+full[20]+' - if (full[23] == 87 ) { '+ echo TESTER +' } \n\ </a>

please note in above if condition "TESTER" is Defines a named constant

but all its not working ...

Answers

  • tester1tester1 Posts: 53Questions: 14Answers: 1

    any one here ?

  • tester1tester1 Posts: 53Questions: 14Answers: 1

    any one here ?

  • dchevalierCACLVdchevalierCACLV Posts: 3Questions: 0Answers: 0

    I'm not real clear on your needs, but I just finally figured out how to use an if else statement in mrender = here's my example:
    (emptypath is a default column setting in mysql, and if thats what is called in the select, then this creates a link to the upload.php file upload script, otherwise it displays a file icon so the file can be viewed/downloaded)

    {
    
    
        'aTargets': [8],
        "mData": 8,
        'mRender': function (data, type, full) {
    
          if (data == '!emptypath!') {
            return '<a href=\"uploadfile.php\">Upload file</a>';
                                                } else {
            return '<a href='+ data +'><i class="fa fa-file fa-lg"></i></a>';
                                                }
                                              }
      }
    
This discussion has been closed.