Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1960
Change the grid height (not the width) on the client
posted

Hello.

I have some code in place to resize the grid when the browser window resizes. I have a jscript method hooked up to the onresize event of the <body> tag.

Inside that method I call the resize(width, height) method of the grid. The problem is that I only want to change the height. I don't ned to mess with the width because it is set at design time to be 100% so that it expands to the total width of the browser.

Is there a way to do that?

 Thanks in advance.

Parents
  • 1960
    Verified Answer
    posted

    Hi.

    After spending some time on this issue, I found a solution. The resize() function changes the width of the grid first and then changes the height. I copied that implementation and removed the code that changes the widht. You have to hook up the onresize event of the form to the OnResized() function defined in the jscript block. the <body> tag should look like this:

     <body onresize="OnResized()">

    Here's the whole jscript code I'm using:

    // Global variable to store the id of the grid

    var gridID;

    // Event handler for the InitializeLayout client-side event

    function UltraWebGrid1_InitializeLayoutHandler(gridName)

    {

    // Store the id of the grid

    gridID = gridName;

    // Adjust the grid's height for the first time

    OnResized();

    }

    // Function to adjust the height of the grid represented by gridID.

    // The grid will adjust to the current height of the browser

    function OnResized()

    {

    // First determine the current height and width of the browser

    // Taken from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

    var myWidth = 0, myHeight = 0;

    if( typeof( window.innerWidth ) == 'number' ) {

    //Non-IE

    myWidth = window.innerWidth;

    myHeight = window.innerHeight;

    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;

    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

    }

     

    // The grid height depends on the available browser height minus a given quantity that changes with the page you are implementing

    gridHeight = myHeight - 300;

     

    // Cap the grid height to a minimum value

    if( gridHeight < 300)

    {

    gridHeight = 300;

    }

    // Retrieve the grid object

    var grid = igtbl_getGridById(gridID);

     

    // The code from this point and on was "borrowed" from Infragistics' resize() implementation.

    // remove the changes to the width and keep the chages to the height.

    if(!ig_csom.IsIE || ((ig_csom.IsIE6 || ig_csom.IsIE7) && igtbl_isXHTML))

    {

    // need to set the width first so we can see whether anything (groupby box) is going to

    // get taller or shorter because of changes to text wrapping

     

    //var marginWidth = igtbl_dom.dimensions.bordersWidth(this.MainGrid);

    //this.MainGrid.style.width = width + "px";

    //document.getElementById(this.Id + "_mc").style.width = (width - marginWidth) >= 0 ? width - marginWidth : 0 + "px";

     

    grid.MainGrid.style.height = 0 +
    "px";

     

    // measure how much space all the fixed elements are going to need

     

    var marginHeight = igtbl_dom.dimensions.bordersHeight(grid.MainGrid);for(var x=0; x<grid.MainGrid.rows.length; x++)

    {

    if(grid.MainGrid.rows[x].id != grid.Id + "_mr")

    {

    marginHeight += grid.MainGrid.rows[x].offsetHeight;

    }

    }

     

     

    if(gridHeight < marginHeight) {

    gridHeight = marginHeight;

    }

     

    // set the new widths and heights of the outer table and rows area

    grid.MainGrid.style.height = gridHeight + "px";

    document.getElementById(grid.Id + "_mr").style.height = (gridHeight - marginHeight) + "px";

    document.getElementById(grid.Id + "_mc").style.height = (gridHeight - marginHeight) + "px";

    }

    else {

    //grid.MainGrid.style.width = width + "px";

    grid.MainGrid.style.height = gridHeight + "px";

    }

    }

     

Reply Children
No Data