2

I'm using the jqGrid plugin for jQuery.

In the jqGrid function, I want to pass in a value for the width, but I want to pass in the value depending on the outcome of a method in my controller.

Controller

public Boolean isTest{ 
    get{
         String userAgent = System.currentPageReference().getHeaders().get('User-Agent');                       

         return userAgent.contains('test');
    }
}

JS

jQuery("#INFO").jqGrid(
                    { 
                        height: 265, 
                        sortable: true,
                        multiselect: false, 
                        viewrecords: true,
                        rowNum: mySelectedRowNum, 
                        width:'{!isTest}' ? pageWidth - 25 : 300,                                        
                    });

At the moment, it's returning true, even when it should be returning false. I use this method in a few different places and it works properly, this is the first time I have used it in a ternary operator though.

Is my implementation wrong somewhere here?

1 Answer 1

3

I would suggest losing the apostrophe at the beginning and end of it. Javascript be me interpreting it as a String the way you are doing it. A String should always evaluate to true, so that may be why it is acting odd. Change it to:

jQuery("#INFO").jqGrid(
{ 
    height: 265, 
    sortable: true,
    multiselect: false, 
    viewrecords: true,
    rowNum: mySelectedRowNum, 
    width:{!isWin8Touch} ? pageWidth - 25 : 300,                                        
});
2
  • 1
    That did the trick, cheers Jesse!
    – Daft
    Nov 13, 2014 at 12:57
  • Awesome! Glad I could help! Nov 13, 2014 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .