Child row: adding a condition on some column

Child row: adding a condition on some column

PandalexPandalex Posts: 32Questions: 8Answers: 1

Hi everyone,

I'm displaying my child row without any issue.
But no I can access my jsp through 2 pages.

I would like to display columns depending on the origin.
I have the information in a session variable :

var site = '${sessionScope.site}';

I want to add a test but it seems to be impossible to do that in the return of the format function:


function format ( d ) { // `d` is the original data object for the row return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+ '<tr>'+ '<td>Field one:</td>'+ '<td>'+d.fieldOne+'</td>'+ '</tr>'+ '<tr>'+ '<td>Field two:</td>'+ '<td>'+d.fieldTwo+'</td>'+ '</tr>'+ '<tr>'+ '<td>Field three:</td>'+ '<td>'+d.fieldThree+'</td>'+ '</tr>'+ if(site == 'T' ) { '<tr>'+ '<td>Conditional field :</td>'+ '<td>'+d.conditionalField+'</td>'+ '</tr>'+ } '</table>'; }

How should can I do this ?

Thx a lot

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited December 2022 Answer ✓

    Create an if condition that builds the HTML string then the return statement can retun the string, for example:

    function format ( d ) {
            // `d` is the original data object for the row
    
            if ( site 'T' )
              {
                 html = '<table>.......</table>';
              } else {
                 html = '<table>.......</table>';
              }
            return html;
        }
    

    Kevin

  • PandalexPandalex Posts: 32Questions: 8Answers: 1
    edited December 2022

    Thx it's perfect, I was wondering if I had to declare a type and what to return

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Just return a string that contains properly formatted HTML.

    Kevin

Sign In or Register to comment.